aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Java Mail Authentication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Mail Authentication" Watch "Java Mail Authentication" New topic
Author

Java Mail Authentication

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
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
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
"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

Joined: Oct 08, 2008
Posts: 492
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
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
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

Joined: Oct 08, 2008
Posts: 492
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
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
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

Joined: Oct 08, 2008
Posts: 492
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Mail Authentication