javax.mail.SendFailedException:无效地址(尝试使用Rediffmail发送emal时)

javax.mail.SendFailedException:无效地址(尝试使用Rediffmail发送emal时),java,email,jakarta-mail,Java,Email,Jakarta Mail,此程序尝试通过首先连接到smtp.rediffmail.com发送电子邮件。没有编译时错误或编译时异常。但当我尝试运行以下程序时,它会生成以下异常 javax.mail.SendFailedException:无效地址; 嵌套异常是: com.sun.mail.smtp.SMTPAddressFailedException:421授权失败:请通过验证 是否先获取消息 我不知道什么是异常,为什么会出现异常 这是完整的程序。在这篇文章中,我尝试与rediffmail服务器建立TLS连接 import

此程序尝试通过首先连接到
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);
              }
   }
}
为什么会出现此异常?

根据:

在您的帐户设置中,启用“登录到传入服务器之前” 在帐户属性的“传出服务器”选项卡上显示“正在发送邮件”。怎么 查找这些属性和选项卡是特定于Outlook版本的,但您 决定信息不重要


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

您正在尝试使用TLS auth,但我在代码中没有看到任何端口设置。通常smtp服务器使用不同的端口进行TLS/SSL身份验证,请尝试通过
mail.smtp.socketFactory.port
进行设置。就我记忆所及,对于TLS,默认值为
587
,对于SSL-
993

    props.put("mail.smtp.socketFactory.port", port);
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

代码的问题在于:

Transport transport = session.getTransport("smtp");
transport.send(msg);

send方法是一个静态方法,您不应该使用Transport类的实例来访问它。它应该是-Transport.send(msg)

我找不到这种选择there@grassPro ... 你为什么到处乱扔-1而不提供反馈或评论?看起来有点傻。TLS真的需要端口设置吗??顺便说一下,SSL也有同样的例外。我正在尝试TLS。请阅读问题