Solved

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

Posted on 2007-11-24
8
4,624 Views
Last Modified: 2013-11-24
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);
      }
}
0
Comment
Question by:fuzzyifs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 11

Expert Comment

by:spoxox
ID: 20345017
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
0
 

Author Comment

by:fuzzyifs
ID: 20347855
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 . . .
0
 
LVL 11

Expert Comment

by:spoxox
ID: 20351377
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

0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 11

Expert Comment

by:spoxox
ID: 20351948
Can you try a different SMTP server?
0
 
LVL 11

Expert Comment

by:spoxox
ID: 20352302
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!
0
 
LVL 11

Accepted Solution

by:
spoxox earned 500 total points
ID: 20354305
With a Yahoo.com email address, you can test their SMTP by making these changes:

mailProperties.put("mail.smtp.host", "smtp.mail.yahoo.com");
mailProperties.put("mail.smtp.port", "465");
mailProperties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
// Yahoo uses SSL

using of course the correct username and password stuff.

Apparently Gmail offers a similar SMTP setup; I haven't tested it but I have read that the Gmail SMTP server is smtp.gmail.com.

Debug log is very similar; the following stuff fits in near the beginning.

DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.com", port 465, isSSL false
220 smtp107.plus.mail.re1.yahoo.com ESMTP
DEBUG SMTP: connected to host "smtp.mail.yahoo.com", port: 465

EHLO george
250-smtp107.plus.mail.re1.yahoo.com
250-AUTH LOGIN PLAIN XYMCOOKIE
250-PIPELINING

0
 

Author Comment

by:fuzzyifs
ID: 20356777
I don't want to use another mail server :(
Maybe it has no solution
0
 
LVL 1

Expert Comment

by:technicvn
ID: 24026610
On Mdaemon configuration; remove "SMTP Server check command and Header for RFC compliance"

or YOU must create your message compliance to RFC.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question