本文介绍了使用interenet向其他人发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码
my code
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMailTLS {
public static void main(String[] args) {
final String username = "[email protected]";//email id 1st
final String password = "xxxxxxx"; //passwd
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.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("[email protected]")); ///email id
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("xxxxxxxx.com"));.//emailid
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
错误
error
Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvQM
534-5.7.14 kXHo4EvbKv_cmLZe8gJv18TKZblj07jc8Hm5Ox3uOVNKA0UwgZ3Q6wx2giu9mbtQFQCQ1I
534-5.7.14 oZrTJ145h7AmtFJnX7X1wLXtiX24Vfq6VsthKkCKtI87ajeuhxIaNyLfsHUVB3MdLi34i5
534-5.7.14 k_lzD0GN7Re_lUFBOssZ1Vv-mEQUQXOlRwhFLXp6ANiONmfayoNFB3a5FeW34Uy3THXq6P
534-5.7.14 isWuZaGIdJae2MJCdTwUQxrZXXws> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 73sm10491911pfh.14 - gsmtp
at SendEmail.SendMailTLS.main(SendMailTLS.java:48)
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvQM
534-5.7.14 kXHo4EvbKv_cmLZe8gJv18TKZblj07jc8Hm5Ox3uOVNKA0UwgZ3Q6wx2giu9mbtQFQCQ1I
534-5.7.14 oZrTJ145h7AmtFJnX7X1wLXtiX24Vfq6VsthKkCKtI87ajeuhxIaNyLfsHUVB3MdLi34i5
534-5.7.14 k_lzD0GN7Re_lUFBOssZ1Vv-mEQUQXOlRwhFLXp6ANiONmfayoNFB3a5FeW34Uy3THXq6P
534-5.7.14 isWuZaGIdJae2MJCdTwUQxrZXXws> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 73sm10491911pfh.14 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:809)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:752)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at SendEmail.SendMailTLS.main(SendMailTLS.java:43)
推荐答案
这篇关于使用interenet向其他人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!