2014-10-19 54 views
-2
Properties props = new Properties(); 

props.setProperty("mail.smtps.host", "smtp.gmail.com"); 
props.setProperty("mail.smtp.port", "465"); 
props.setProperty("mail.smtp.starttls.enable","true"); 
props.setProperty("mail.debug", "true"); 
props.setProperty("mail.smtps.auth", "true"); 
props.setProperty("mail.smtp.socketFactory.port", "465"); 
props.setProperty("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); 
props.setProperty("mail.smtp.socketFactory.fallback", "false"); 

Authenticator auth = new SMTPAuthenticator(login, password); 

Session session = Session.getInstance(props, auth); 
session.setDebug(true); 
try 
{  
    MimeMessage msg = new MimeMessage(session); 
    msg.setText(message); 
    msg.setSubject(subject); 
    msg.setFrom(new InternetAddress(from)); 
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); 

    Transport.send(msg); 
} 

我試圖通過servlet.But我越來越MessagingException在此code.And最有可能發送一封電子郵件,該異常是由Transport.send(MSG)。如何我可以出去扔這個的?由小服務程序發送電子郵件

+0

具有u包括相同的API ??? – Krishna 2014-10-19 10:35:09

+1

堆棧跟蹤請? – SMA 2014-10-19 10:36:01

+0

如果我沒有錯,那麼屬性應該是System.getprpoerties(); – Krishna 2014-10-19 10:38:51

回答

相關問題