In JavaMail, how to authenticate to the smtp server (530 MAIL requies AUTH)
To the experienced and gurus:
I am trying JavaMail. The Java class is written in JDeveloper 11.1.1.3, with a main() method. The code was compiled with no error.
When the java code is run, I got in the console the message "530 ... MAIL requires AUTH". Obviously it is asking for user name and password. I searched on the internet for clues, and added some code for that:
<pre>
properties.put("mail.smtp.user", user);
properties.put("mail.smtp.password", password);
properties.put("mail.smtp.auth", true);
Session mail_session = Session.getDefaultInstance(properties, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
</pre>
Again the code compiled with no error, and again I got the 530 error, which I realized was from smtp, as I tried telnet'ing to the mail server on port 25 and got exactly the same error message.
Now the question is how to submit the credentials in a way the smtp server will be pleased to accept. This much I know about the network and servers:
1. When I do telnet smtp.server 25 on a unix machine which is in the same VLAN with the smtp server, authentication is not even required.
2. But I am trying sending email using the JavaMail code on a PC that is in a different VLAN. At a DOS command prompt on the PC, after "mail From: ...." I received "MAIL requires AUTH".
3. In response to the message, I typed STARTTLS, and received "220 Go Ahead". But I do not know how to go ahead and do what (I do have valid accounts to use). Anything I tried typing in response to the "Go Ahead" would get me cut off from the server (The message was "Connection to server lost"). If I knew how to respond to the "Go Ahead", the next thing would be to do the same in my JavaMail code. But I don't know how.
I guess with ever tightening security, the answer to the question may be dependent on the security setting on the network and the servers. If that is the case, what are the step I should take to find a solution? Any ideas, suggestions and guidance are very much appreciated.
Newman
Edited by: J. Newman on Dec 7, 2010 11:04 PM