次のコードがあります。
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.PasswordAuthentication;
public class Alpha{
public static void main (String[] args){
final String username = "myemail@gmail.com";
final String password = "mypassword";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smpt.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication (username, password);
}
});
try{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("emailfrom@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("email.to@gmail.com"));
message.setSubject("Test Email");
message.setText("Message");
Transport.send(message);
System.out.println("The message was sent");
} catch (MessagingException e){
throw new RuntimeException(e);
}
}
}
しかし、このエラーが発生し続けます:
Exception in thread "main" java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. p3sm47032789wjf.49 - gsmtp
at Alpha.main(Alpha.java:46)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. p3sm47032789wjf.49 - gsmtp
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at Alpha.main(Alpha.java:40)
私は周りを見回して、props.put("mail.smpt.starttls.enable", "true");という行で同様の質問に対する答えを見つけましたが、それでも機能せず、途方に暮れています何をすべきか!