I'm using latest mail.jar, latest activation.jar, jdk6.
My JavaMail util uses authorization credentials and works fine with my test mail server, but it fails with "javax.mail.NoSuchProviderException: smtp" when I try using my production mail server. The only difference is the connection url and credentials. The production mail server works fine when I use an external pop3 mail client to send/receive (i.e Outlook). The util that sends the mail is contained in a web app running under Tomcat.
I did see earlier topics on this subject but none ever gave a conclusive solution.
I sincerely appreciate any help! - the code follows.
Thanks,
--Bob
Properties properties = System.getProperties();
properties.put("mail.smtp.host", hostStr);
properties.put("mail.smtp.auth", true);
Authenticator auth = new PopupAuthenticator(userStr, passStr);
Session session = Session.getInstance(properties, auth);
session.setDebug(true);
Transport tr = session.getTransport("smtp");
tr.connect(hostStr, userStr, passStr);
MimeMessage message = new MimeMessage(session);
Address fromAddress = new InternetAddress(sndrAddr);
message.setRecipients(Message.RecipientType.TO, toAddresses);
message.setFrom(fromAddress);
message.setSubject(msgSubj);
message.setText(msgBody);
Transport.send(message);
...
static class PopupAuthenticator extends Authenticator {
String username;
String password;
public PopupAuthenticator(String username,String password){
this.username=username;
this.password=password;
}
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,password);
}
}
Edited by: rgc3679 on Dec 2, 2009 12:49 AM