com.sun.mail.smtp.SMTPSendFailedException:550访问被拒绝 - 无效的HELO名称(参见RFC2821 4.1.1.1)

时间:2017-09-25 04:35:33

标签: java performance javamail

public static void main(String [] args){  

  String to="xyz@gmail.com";//change accordingly  
  final String user="abc@gmail.com";//change accordingly  
  final String password="xxxxxx";//change accordingly

  Properties pro = System.getProperties();
  pro.setProperty("mail.smtp.host", "mail.javatpoint.com");  
  pro.put("mail.smtp.auth", "true");

  Session session = Session.getDefaultInstance(pro,  new javax.mail.Authenticator() {  
       protected PasswordAuthentication getPasswordAuthentication() {  
           return new PasswordAuthentication(user,password);  
           }  
          });    

  try{
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(user));
      message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));  
      message.setSubject("certificate");  

      BodyPart msg = new MimeBodyPart();
      msg.setText("bodyPartMsg");

      MimeBodyPart messageBodyPart2 = new MimeBodyPart();  
      System.out.println("attach");
        String filename = "C:\\Users\\Rudresh Mehta\\Desktop\\flow for certiManipulator";//change accordingly  
      System.out.println("attach complete");
        DataSource source = new FileDataSource(filename);  
        messageBodyPart2.setDataHandler(new DataHandler(source));  
        messageBodyPart2.setFileName(filename);

        Multipart multipart = new javax.mail.internet.MimeMultipart();

        multipart.addBodyPart(msg);  
        multipart.addBodyPart(messageBodyPart2);  


        //6) set the multiplart object to the message object  
        message.setContent(multipart );  
        //7) send message  

*我的问题是为什么当它来到这里时,一旦发送传输它就会在catch中移动然后从中移出并且不发送邮件,并且如标题中提到的那样,当e是时,错误显示在catch中打印。*             Transport.send(消息);
           System.out.println("消息发送....");

  }catch(Exception e)
  {
      System.out.print(e);
      System.out.println("in catch");
  }
  System.out.println("complete");

1 个答案:

答案 0 :(得分:0)

如果没有正确提取您的本地主机名,请将mail.smtp.localhost属性设置为您的主机名。