Hi, I try to send an email using the JavaMail api and the JAMES server.
The JAMES SMTP authentication feature is on.
But it doesn't work to send an email.
I have searched in the Bug database for an entry, which describes a SMTP
AUTH Bug. No matching Bug found. I'm not sure whether this is a Bug or ?
The source code for my test class is ?
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class JAMESSMTPAuthenticationTest {
private Session session;
/**
* @param args args[0] recipient email address
*/
public static void main(String[] args) {
JAMESSMTPAuthenticationTest jt = new
JAMESSMTPAuthenticationTest();
jt.getMailSession();
jt.sendMail(args[0]);
}
private void getMailSession() {
Properties props = new Properties();
props.put("mail.debug", "true");
props.put("mail.smtp.auth","true");
session = Session.getDefaultInstance(props, new
TestAuthenticator());
}
private void sendMail(String recipient) {
try {
MimeMessage mm = new MimeMessage(session);
mm.setFrom(new InternetAddress("[EMAIL PROTECTED]"));
mm.addRecipient(Message.RecipientType.TO, new
InternetAddress(recipient));
mm.setSubject("JAMESSMTPAuthenticationTest...");
Transport.send(mm);
} catch(Exception e) {
System.out.println("Exception: ");
System.out.println(e);
e.printStackTrace();
}
}
private final class TestAuthenticator extends Authenticator {
/**
* @see java.util.Authenticator.getPasswordAuthentication()
*
*/
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("test", "123456");
}
}
}
This source code doesn't work.
Exception message output:
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 530 Authentication Required
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 530 Authentication Required
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at
JAMESSMTPAuthenticationTest.sendMail(JAMESSMTPAuthenticationTest.java
:38)
at
JAMESSMTPAuthenticationTest.main(JAMESSMTPAuthenticationTest.java:18)
Another test class source code ?
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class JAMESSMTPAuthenticationTest2 {
private Session session;
/**
* @param args args[0] recipient email address
*/
public static void main(String[] args) {
JAMESSMTPAuthenticationTest2 jt = new
JAMESSMTPAuthenticationTest2();
jt.getMailSession();
jt.sendMail(args[0]);
}
private void getMailSession() {
Properties props = new Properties();
props.put("mail.debug", "true");
props.put("mail.smtp.auth","true");
session = Session.getDefaultInstance(props, null);
}
private void sendMail(String recipient) {
try {
MimeMessage mm = new MimeMessage(session);
mm.setFrom(new InternetAddress("[EMAIL PROTECTED]"));
mm.addRecipient(Message.RecipientType.TO, new
InternetAddress(recipient));
mm.setSubject("JAMESSMTPAuthenticationTest...");
mm.setText("Blablabla");
Transport tr = session.getTransport("smtp");
tr.connect("localhost", "test", "123456");
mm.saveChanges();
tr.sendMessage(mm, mm.getAllRecipients());
tr.close();
} catch(Exception e) {
System.out.println("Exception: ");
System.out.println(e);
e.printStackTrace();
}
}
}
This source code works if you use a local email address as recipient. Why?
If you use another email address as recipient (E.g.. [EMAIL PROTECTED]) then it
doesn't work. The specified user name and password has no
influence. Why?
Exception message output:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 530 Authentication Required
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 530 Authentication Required
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:804)
at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:320)
at
JAMESSMTPAuthenticationTest2.sendMail(JAMESSMTPAuthenticationTest2.ja
va:43)
at
JAMESSMTPAuthenticationTest2.main(JAMESSMTPAuthenticationTest2.java:1
8)
Test environment:
OS: MS Windows 2000
JDK: 1.3
JavaMail: 1.2
JAMES: James 2.0a2
Thanx
Bye
michi