gpt4 book ai didi

javax.mail.SendFailedException : Invalid Addresses (While trying to send emal using Rediffmail)

转载 作者:行者123 更新时间:2023-12-01 05:43:06 28 4
gpt4 key购买 nike

此程序尝试通过首先连接到 smtp.rediffmail.com 来发送电子邮件。没有编译时错误或编译时异常。但是当我尝试运行以下程序时,它会生成以下异常。

javax.mail.SendFailedException:地址无效; 嵌套异常是: com.sun.mail.smtp.SMTPAddressFailedException:421 授权失败:请通过以下方式进行身份验证 首先获取消息

我无法弄清楚异常是什么以及为什么我会收到此异常。

这是完整的程序。在此我尝试与 rediffmail 服务器建立 TLS 连接。

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

class rediff {
public static void main(String args[]) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.rediffmail.com");
props.put("mail.stmp.user", "from");

//To use TLS
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.password", "password");

Session session = Session.getDefaultInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
String username = "from";
String password = "password";
return new PasswordAuthentication("from", "password");
}
});
String to = "me@gmail.com";
String from = "from@rediff.com";
String subject = "Testing...";
MimeMessage msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(from));
msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText("rediff program working...!");
Transport transport = session.getTransport("smtp");
transport.send(msg);
System.out.println("fine!!");
} catch(Exception exc) {
System.out.println(exc);
}
}
}

为什么我会收到此异常?

最佳答案

按照:http://www.techtalkz.com/microsoft-outlook/193842-pop3.html

In your account settings, enable the "Log on to incoming server before sending mail" on the "Outgoing Server" tab of your account properties. How to locate these properties and tabs is Outlook version-specific but you decided that information wasn't important.

该错误特定于您尝试从客户端使用的 SMTP 服务。这不是代码问题。检查您的 rediffmail.com 帐户设置

关于javax.mail.SendFailedException : Invalid Addresses (While trying to send emal using Rediffmail),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6633573/

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