com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

Viewed 1893
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  

* my question is why when it comes here than as soon as transport is given it moves in catch and then out of it and mail is not sent and as mention in title that error is shown in catch when e is print.* Transport.send(message);
System.out.println("message sent....");

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

If it's not picking up your local host name properly, set the mail.smtp.localhost property to your host name.

Related