0

I am getting this error only when I try to send mail using javax library. If i send it from my mail client, it works fine.

Properties properties = new Properties();
        properties.put("mail.transport.protocol", "smtp");
        properties.put("mail.smtp.host",server); // smtp.gmail.com?
        //properties.put("mail.smtp.port", "25");
        properties.put("mail.smtp.auth", "true");
        Authenticator authenticator = new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, pass);
            }
        };
        Session session = Session.getDefaultInstance(properties, authenticator);
         Message message =new MimeMessage(session);
         message.setFrom(new InternetAddress("alert@test.com"));
         message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("alert1@test.com",false));
         message.setSubject("test");
         message.setText("hi");        
         Transport.send(message);
         System.out.println("mail sernt");

I went through these posts, https://stackoverflow.com/questions/24688111/smtp-554-analysis ,SMTP: Error 554, message is not RFC compliant , What does props.put("mail.smtp.host", host) in JavaMail do? All of these seem to suggest that IP address may be blocked / something related to SMTP. However, my mail client works fine. Is that related to SMTP config or have I missed something .?

When I try to debug, I get file not found exception for : jre1.6.0\lib\javamail.providers and javamail.address.map. Is that related to these exceptions. Also how do I check if my firewall is not the problem.

Community
  • 1
  • 1
Bhuvaneshwari
  • 82
  • 2
  • 16
  • put another property `properties.put("mail.smtp.starttls.enable", "true");` – Deb Sep 09 '14 at 10:18
  • @ricky2527 Adding that gets me javax mail exception : ' javax.mail.MessagingException: Can't send command to SMTP host; nested exception is: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target' – Bhuvaneshwari Sep 09 '14 at 10:23
  • You can find solution of this problem here. http://stackoverflow.com/questions/14771061/javax-mail-messagingexception-cant-send-command-to-smtp-host). – Deb Sep 09 '14 at 10:32

3 Answers3

0

I was getting that response (Error 554 Message does not conform to standards) but it stopped when I changed the mail from format to this:

"<alert@test.com>"

Please try if it helps.

klarki
  • 915
  • 4
  • 13
  • Hi @klarki , Thanks for your response. I Tried this. I again get the message saying message does not conform to 554 standards. – Bhuvaneshwari Sep 11 '14 at 05:00
0

Are you able to solve the problem? I tried that it didn't give any exception and I hardly change something from your code. Please take a look at it if it's help you.

    final String username = "myUserName";   //enter your user name
    final String password = "myPassword";  //enter password

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "");       //enter host name
    props.put("mail.smtp.port", "");       //enter port no here

    Session session = Session.getInstance(props,
            new javax.mail.Authenticator(myUserName) {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(userName, password);
                }
            });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(userName));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("reciverMailAddress"));
        message.setSubject("Test");
        message.setText("This is the body of the email");
        Transport.send(message);

        System.out.println("Done");


    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }
}
Deb
  • 2,922
  • 1
  • 16
  • 32
  • I tried all these, and tried running InstallCert from the links that you had mentioned, from installCert I am not able to connect to the host but I am able to ping. Now, I am confused if it is a network(firewall) issue or code issue. – Bhuvaneshwari Sep 11 '14 at 06:40
  • The code is working fine from my end, so it must be firewall issue or something else. – Deb Sep 11 '14 at 06:51
  • I think it's not a firewall problem, it's like you stated, "something else". Most probably smtp server configuration that requires some standard to be fulfilled. – klarki Sep 11 '14 at 09:30
0

The issue was with the date.The message "Message does not conform to 554 standards was because of date. Adding

message.setSentDate(new Date());

fixed the issue.

this SMTP: Error 554, message is not RFC compliant helped.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Bhuvaneshwari
  • 82
  • 2
  • 16