Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I connect to an SMTP server that requires a username and password?

843830Apr 25 2006 — edited Apr 26 2006
Hi,

I am currently working on a project for university which requires me to send and receive email. I was until this week able to send mail no problem, but now the SMTP server has been upgraded so that each time a mail is sent it requires the username and password.

Ideally the connection should be made using TLS/SSL, and not use the Authenticator method. I want to pass the username and password directly if possible.

I've been trying to use the following but have been getting handshake, and other exceptions:
SMTPSSLTransport smtpSSLtransport = new SMTPSSLTransport(session, 
                    new URLName("smtp", smtpHost, port, null-File,
                    "USERNAME", "PASSWORD"));
        smtpSSLtransport.setStartTLS(true);
        smtpSSLtransport.connect(new Socket(smtpHost, port));
        smtpSSLtransport.sendMessage(smtpMessage,                                                     message.getAllRecipients());
        smtpSSLtransport.close();
Can anyone correct this piece of code for me or point me in the right direction of what classes and methods I should be using?

Many thanks in advance,

Gordon
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2006
Added on Apr 25 2006
2 comments
328 views