gpt4 book ai didi

java - 发送失败异常: bad password

转载 作者:行者123 更新时间:2023-12-01 13:41:12 24 4
gpt4 key购买 nike

这个问题已经从一个相当模糊的问题演变成了一个更加明确的问题。该代码来自 example by mkyong 。至少根据谷歌的说法,it's a bad password ,我已遵循他们的登录建议。当然,当我输入正确的密码时,我会得到相同的结果,下面的密码是一个虚拟的。无论密码如何,输出都是相同的。

输出:

BUILD SUCCESSFUL
Total time: 1 second
-- listing properties --
mail.smtp.gmail=smtp.gmail.com
mail.smtps.quitwait=true
mail.smtp.username=hawat.thufir@gmail.com
mail.smtp.starttls.enable=true
mail.smtp.connectiontimeout=2000
mail.smtp.user=hawat.thufir
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.password=password
nntp.host=nntp://localhost/
mail.smtp.socketFactory.port=465
mail.smtp.timeout=2000
mail.imap.port=993
mail.imap.timeout=5000
mail.smtp.port=587
mail.smtp.auth=true
mail.imap.host=imap.gmail.com
mail.nntp.newsrc.file=/home/thufir/.newsrc
mail.imap.connectiontimeout=5000
mail.smtp.host=smtp.gmail.com

========message follows==========

Exception in thread "main" java.lang.RuntimeException: javax.mail.SendFailedException: Send failed;
nested exception is:
javax.mail.SendFailedException: 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 g6sm55120721pat.2 - gsmtp
at net.bounceme.dur.nntp.SendTLS.sendMessage(SendTLS.java:61)
at net.bounceme.dur.nntp.SendTLS.<init>(SendTLS.java:23)
at net.bounceme.dur.nntp.SendTLS.main(SendTLS.java:34)
Caused by: javax.mail.SendFailedException: Send failed;
nested exception is:
javax.mail.SendFailedException: 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 g6sm55120721pat.2 - gsmtp
at javax.mail.Transport.doSend(Transport.java:231)
at javax.mail.Transport.send(Transport.java:75)
at net.bounceme.dur.nntp.SendTLS.sendMessage(SendTLS.java:57)
... 2 more
thufir@dur:~/NetBeansProjects/MailFromNNTP$

代码:

public class SendTLS {

public SendTLS() {
try {
sendMessage();
} catch (NoSuchProviderException ex) {
Logger.getLogger(SendTLS.class.getName()).log(Level.SEVERE, null, ex);
} catch (MessagingException ex) {
Logger.getLogger(SendTLS.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SendTLS.class.getName()).log(Level.SEVERE, null, ex);
}
}

public static void main(String[] args) {
new SendTLS();
}

private void sendMessage() throws NoSuchProviderException, MessagingException, IOException {
Properties props = PropertiesReader.getProps();
props.list(System.out);
System.out.println("\n========message follows==========\n");
final String username = props.getProperty("mail.smtp.username");
final String password = props.getProperty("mail.smtp.password");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {

@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from-email@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to-email@gmail.com"));
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);
}
}
}

最佳答案

由于您正在连接到 Gmail。使用这些属性

prop.put("mail.smtp.starttls.enable", "true"); 
prop.put("mail.smtp.host", host);
prop.put("mail.smtp.user", from);
prop.put("mail.smtp.password", pass);
prop.put("mail.smtp.port", "465");
prop.put("mail.smtp.auth", "true");

另请参阅此 http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes

*Post was modified after answering, answer may no longer be relevant*

关于java - 发送失败异常: bad password,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20758032/

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