gpt4 book ai didi

JavaMail STARTTLS 错误?

转载 作者:行者123 更新时间:2023-11-30 03:40:19 26 4
gpt4 key购买 nike

我有以下代码:

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");,但它仍然不起作用,而且我在失去了该怎么办!

最佳答案

您的属性名称有拼写错误:

mail.smtp.starttls.enable

而不是

mail.smpt.starttls.enable

关于JavaMail STARTTLS 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26956742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com