com.sun.mail.smtp.SMTPSendFailedException:530-5.5.1需要验证

 beilei_beike_516 发布于 2023-02-08 10:11

我正在尝试从我的Java应用程序向任何特定的电子邮件地址发送电子邮件.我正在使用Java Mail API但不幸的是我收到了SMTPSendFailedException错误.任何人都可以告诉我我在哪里犯了错误.这是我的代码

import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

//import SeconMail.Authenticator;

public class SendMail
{

   public static void main(String [] args)
   {    

      // Recipient's email ID needs to be mentioned.
      String to = "to@gmail.com";

      // Sender's email ID needs to be mentioned
      String from = "from@expertflow.com";

      // Assuming you are sending email from localhost
      String host = "smtp.gmail.com";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server

      properties.setProperty("mail.smtp.host", host);


      properties.put("mail.smtp.starttls.enable", "true");

      properties.put("mail.smtp.auth", "false");
      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);
      session.setDebug(true);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("This is actual message");

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}

小智.. 6

properties.setProperty("mail.smtp.user", "abc");
properties.setProperty("mail.smtp.password", "xyz");
properties.setProperty("mail.smtp.auth", "true"); 

请尝试使用此

1 个回答
  • properties.setProperty("mail.smtp.user", "abc");
    properties.setProperty("mail.smtp.password", "xyz");
    properties.setProperty("mail.smtp.auth", "true"); 
    

    请尝试使用此

    2023-02-08 10:12 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有