• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail Authentication

 
Meet Gaurav
Ranch Hand
Posts: 492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While I was goggling I got the below link and that says "Username and password is generally not needed to send e-mail although your ISP may still require it to prevent spam from going through its systems."

http://www.vipan.com/htdocs/javamail.html

While I was trying without username and password am getting below exception. Please assist me how to send mail with out username and password

java.net.ConnectException: Connection timed out (errno:238)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at com.iflex.pdfmailutilities.mail.EmailSender.sendEmail(EmailSender.java:140)
at com.iflex.pdfmailutilities.mail.EmailSender.sendMail(EmailSender.java:179)
at com.iflex.pdfmailutilities.mail.EmailSender.main(EmailSender.java:164)
Caused by: java.net.ConnectException: Connection timed out (errno:238)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:462)
at java.net.Socket.connect(Socket.java:412)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Username and password is generally not needed to send e-mail although your ISP may still require it to prevent spam from going through its systems."

That was true in the days of dial-up, where the ISP's mail server knew that the client was an authenticated user. These days -with connections made over TCP/IP from potentially anywhere- authentication is almost always required.

But the error message sounds more like a general connection problem than something related to authentictaion. Can you telnet to port 25 of the SMTP server?
 
Meet Gaurav
Ranch Hand
Posts: 492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this code using the link earlier I possted. But this never used userid and password. Is there any other way to connect to SMTP with out userid and password

 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Times have changed; you need to get used to using authentication with SMTP. The JavaMail tutorial linked from the JavaRanch JEE FAQ has code samples for that.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to identify whether the STMP server requires authentication or not. I heard some open SMTP servers are there and they dont require any user id and password for sending email.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No reputable ISP or hosting company runs open SMTP relays any more these day. They'd be blacklisted everywhere fast.

The error message you get when trying to connect to an SMTP without authentication will indicate that it is an authentication problem; so that's a clue :-)
 
Meet Gaurav
Ranch Hand
Posts: 492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when I tried with the same program with authentication I mean simply pass the user id and password to connect and its working fine. If i tried to connect directly without userid and password am getting this below exception. Don't know wats happening

java.net.ConnectException: Connection timed out (errno:238)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at com.iflex.pdfmailutilities.mail.EmailSender.sendEmail(EmailSender.java:140)
at com.iflex.pdfmailutilities.mail.EmailSender.sendMail(EmailSender.java:179)
at com.iflex.pdfmailutilities.mail.EmailSender.main(EmailSender.java:164)
Caused by: java.net.ConnectException: Connection timed out (errno:238)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:462)
at java.net.Socket.connect(Socket.java:412)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic