を使用して特定の電子メール ID にメールを送信する簡単な Java プログラムを作成しています。java mail using SSL
以下は私のコードです
public static String sendMail(String to)
{
String status_message = null;
try
{
Properties props = new Properties();
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("sender@gmail.com","password");//change accordingly
}
});
//compose message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("sender@gmail.com"));//change accordingly
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Email Subject");
message.setText("Text Content included in inside Email");
//send message
Transport.send(message);
status_message = "success";
}
catch (MessagingException ex)
{
status_message = ex.getMessage();
}
}
特定の main Thread内でこのコードを実行したとき。うまくいきました。
しかし、私がそれを含めたとき、これはうまくいきませんでしたinside a function called within a servlet
status_message 値を読んだとき。を示していsmtp
ます。
誰でも問題が何であるかを知るのを手伝ってくれますか? 私は何か不足していますか?jsp サーブレットを介してメールを送信したい。