gpt4 book ai didi

java - 553 抱歉,身份验证失败或超时。请先收到消息以验证自己的身份。(#4.4.3)

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

我正在尝试使用 Java Mail API 发送邮件,但由于发生以下错误而无法发送邮件

553 sorry, Authentication failed or timed out. Please do get messages first to authenticate yourself.(#4.4.3)

我无法理解问题发生在哪里或者 rediff 是否有任何特殊设置?我用谷歌搜索但没有找到解决方案。请帮我纠正它

这是我的代码

import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

import java.util.Properties;


public class TestMail {

public static void main(String[] args) throws Exception{
new TestMail().test();
}

public void test() throws Exception{
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "smtp.rediffmailpro.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", 587);
// props.put("mail.smtp.starttls.enable", "true");


Authenticator auth = new SMTPAuthenticator();
Session mailSession = Session.getDefaultInstance(props, auth);
// uncomment for debugging infos to stdout
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);
message.setContent("This is a test", "text/plain");
message.setFrom(new InternetAddress("xxxxxxxxxxx"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("xxxxxxxxxxxxxxxxxx@gmail.com"));

transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
//Transport.send(message);

}

private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username = "xxxxxxxxx";
String password = "xxxxxxxx";
return new PasswordAuthentication(username, password);
}
}
}

最佳答案

为了防止被用来发送垃圾邮件,大多数 SMTP 服务器在您尝试使用它们来中继邮件(即将邮件发送到其他服务器)时都要求进行某种身份验证。

这可以是连接到服务器时提供的用户和密码。其他服务器 - 似乎就是这种情况 - 要求您首先使用 POP3 或 IMAP 连接它们(您必须发送身份验证)。他们会记住您的 IP 地址已成功用于经过身份验证的连接,并在此后的一段时间内允许 SMTP 中继请求。

检查这种情况的一种方法是使用您的邮件程序来获取邮件,然后立即从同一台计算机(或至少通过相同的互联网连接)运行您的程序来发送邮件。

如果这有效,您必须在发送邮件之前在应用程序中建立 POP3 连接,或者与您的邮件提供商联系是否有其他方法来验证 SMTP 连接。

关于java - 553 抱歉,身份验证失败或超时。请先收到消息以验证自己的身份。(#4.4.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27437188/

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