Seam 2 and javax.mail.NoSuchProviderException: smtp
br3t3s Jul 1, 2012 2:48 PMHi!
I have a problem with sending mail using Java Mail API. I've added dependencies on my EAR project pom.xml.
<dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1</version> <scope>provided</scope> </dependency>
When I'm running my app on JBoss 6.1 and execute action always see on console log javax.mail.NoSuchProviderException: smtp.
I don't want to use Seam Mail. I'm trying to write my own simple mail client.
Can anyone tell me how to configure Seam application to avoid javax.mail.NoSuchProviderException: smtp ?
My test bean sending a mail
@Scope(ScopeType.PAGE)
@Name("message")
public class MessageBean {
public void send() {
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("test@gmail.com",
"aaa");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("test@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("test@gmail.com"));
message.setSubject("Testing Subject");
message.setText("Test message text!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}