Link to home
Start Free TrialLog in
Avatar of fuzzyifs
fuzzyifs

asked on

Have problem when sending an email using JAVA-MAIL, MDaemon server

I write a small code to send an email, but there is an error: com.sun.mail.smtp.SMTPSendFailedException: 554 Message does not conform to standards

Here is listing:

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class demo {
  public static void main (String args[]) throws Exception {


    String host = "mail.aivietnam.net";
    String from = "didulich@aivietnam.net";
    String to = "thangdq@aivietnam.net";
    String userName = "didulich@aivietnam.net";
    String password = "mypassword"; // this is dumy password, in fact i have tried with real password


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

    // Setup mail server
    props.put("mail.smtp.host", host);
    props.put("mail.transport.protocol", "smtp");

      props.put("mail.smtp.port", 25);
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable","true");      // sua exception StartTLS
      props.put("mail.smtp.quitwait", "false");

    // Get session
    Session session = Session.getDefaultInstance(props, new MyAuthenticator(userName, password));

    // Define message
    MimeMessage message = new MimeMessage(session);

    // Set the from address
    message.setFrom(new InternetAddress(from));

    // Set the to address
    message.addRecipient(Message.RecipientType.TO,
      new InternetAddress(to));

    // Set the subject
    message.setSubject("Hello JavaMail");

    // Set the content
    message.setText("Welcome to JavaMail");

    // Send message
    Transport.send(message);
  }
}

class MyAuthenticator extends Authenticator
{
      private String userName;
      private String password;

      MyAuthenticator()
      {
            super();
      }

      MyAuthenticator(String userName, String password)
      {
            super();
            this.userName = userName;
            this.password = password;
      }

      protected PasswordAuthentication getPasswordAuthentication()
      {
            return new PasswordAuthentication(userName, password);
      }
}
Avatar of spoxox
spoxox
Flag of Canada image

I changed the from, to, and host info. The SMTP server I use processes this code properly.

http://www.answersthatwork.com/Download_Area/ATW_Library/Networking/Network__3-SMTP_Server_Status_Codes_and_SMTP_Error_Codes.pdf
says some change to the message and/or destination must be made. As I changed the destination in my test, this should be checked.

You might try session.setDebug(true); you might also enclose the code in a try..catch for more info.

FYI: regarding props.put("mail.smtp.port", 25);
The properties are always set as strings. I use a different port, and without the quotes it was defaulting to port 25 - so you aren't having a problem with this, but you might like to fix it anyway.
see http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html
Avatar of fuzzyifs
fuzzyifs

ASKER

thanks for your reply!
i tried to use Debug, and enclose the code in a try..catch, and it's my console monitor :

DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s
mtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "mail.aivietnam.net", port 25, isSSL false

220 aivietnam.net ESMTP MDaemon 9.5.5; Mon, 26 Nov 2007 08:51:28 +0700
DEBUG SMTP: connected to host "mail.aivietnam.net", port: 25

EHLO thangdq
250-aivietnam.net Hello localhost, pleased to meet you
250-ETRN
250-AUTH=LOGIN
250-AUTH LOGIN CRAM-MD5
250-8BITMIME
250 SIZE 0
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN CRAM-MD5"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "0"
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
ZGlkdWxpY2hAYWl2aWV0bmFtLm5ldA==
334 UGFzc3dvcmQ6
YWl2aWV0bmFt
235 Authentication successful
DEBUG SMTP: use8bit false
MAIL FROM:<didulich>
250 <didulich@aivietnam.net>, Sender ok
RCPT TO:<thangdq@aivietnam.net>
250 <thangdq@aivietnam.net>, Recipient ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   thangdq@aivietnam.net
DATA
354 Enter mail, end with <CRLF>.<CRLF>
From: didulich
To: thangdq@aivietnam.net
Message-ID: <30246505.0.1196041740937.JavaMail.javamailuser@localhost>
Subject: Hello JavaMail
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Welcome to JavaMail
.
554 Message does not conform to standards
DEBUG SMTP: got response code 554, with response: 554 Message does not conform t
o standards

RSET
250 RSET? Well, ok.
com.sun.mail.smtp.SMTPSendFailedException: 554 Message does not conform to stand
ards

        at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
515)
        at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637)
        at javax.mail.Transport.send0(Transport.java:189)
        at javax.mail.Transport.send(Transport.java:118)
        at demo.main(demo.java:61)
QUIT
com.sun.mail.smtp.SMTPSendFailedException: 554 Message does not conform to stand
ards

        at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
515)
        at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637)
        at javax.mail.Transport.send0(Transport.java:189)
        at javax.mail.Transport.send(Transport.java:118)
        at demo.main(demo.java:61)
Press any key to continue . . .
My debug log is very similar - but without the error! (My smtp server is Postfix.)

I tried exchanging the set content statement with code from an example on page 90 of the JavaMail API Design Specification (available at http://java.sun.com/products/javamail/JavaMail-1.4.pdf). That code (shown below) also worked for me. Maybe it will make MDaemon happier.

BTW, I accidentally sent an email to the thangdq address shown above using this new code, but at least it shows that JavaMail and Postfix don't have a problem with that address.
//-----------------------------------------------------------
  // Set the content
  //message.setText("Welcome to JavaMail");
  
  // create and fill the first message part
  String msgText1 = "This is a message body.\nHere's line two.";
  String msgText2 = "This is the text in the message attachment.";
  
  MimeBodyPart mbp1 = new MimeBodyPart();
  mbp1.setText(msgText1);
 
  // create and fill the second message part
  MimeBodyPart mbp2 = new MimeBodyPart();
  // Use setText(text, charset), to show it off !
  mbp2.setText(msgText2, "us-ascii");
  // create the Multipart and its parts to it
  Multipart mp = new MimeMultipart();
  mp.addBodyPart(mbp1);
  mp.addBodyPart(mbp2);
  // add the Multipart to the message
  message.setContent(mp);
//-----------------------------------------------------------			

Open in new window

Can you try a different SMTP server?
I installed MDaemon 9.6 locally (I have never used it; don't have any specific configuration knowledge), created a local domain and successfully sent email using the MDaemon SMTP server and this javax.mail program. The debug output is basically identical, line for line, until your 554 message.

I can find no table of error messages for MDaemon.

So...I don't know what else to tell you except good luck - and try a different SMTP server if you can!
ASKER CERTIFIED SOLUTION
Avatar of spoxox
spoxox
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't want to use another mail server :(
Maybe it has no solution
On Mdaemon configuration; remove "SMTP Server check command and Header for RFC compliance"

or YOU must create your message compliance to RFC.