com.sun.mail.smtp.SMTPSendFailedException:530-5.5.1需要身份验证 [英] com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required

查看:688
本文介绍了com.sun.mail.smtp.SMTPSendFailedException:530-5.5.1需要身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Java应用程序中的电子邮件发送到任何特定的电子邮件地址。
我正在使用Java Mail API,但不幸的是我收到SMTPSendFailedException错误。谁能告诉我我在哪里做错了。这是我的代码

I am trying to send an Email from my Java Application to any particular email address. I am using Java Mail API but Unfortunately i am getting SMTPSendFailedException error. Can any body tell me where i am doing a mistake. Here is my code

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();
      }
   }
}


推荐答案

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

请尝试使用此

这篇关于com.sun.mail.smtp.SMTPSendFailedException:530-5.5.1需要身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆