0
votes

I want to use the gmx smtp server to send some mails with java mail. All i get is this exception, the page which i should review in the exception doesnt provide me information how to fix this issue.

com.sun.mail.smtp.SMTPSendFailedException: 553 5.1.7 Complete address with domain, please ( http://portal.gmx.net/serverrules ) {mp032}
;
  nested exception is:
        com.sun.mail.smtp.SMTPSenderFailedException: 553 5.1.7 Complete address with domain, please ( http://portal.gmx.net/serverrules ) {mp032}

I implemented it in Java as following:

props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "mail.gmx.net");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.from", "test@test.test);
props.put("username", "SOMEUSERNAME@gmx.at");
props.put("password", "SOMEPASS");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.debug", "true");

Authenticator auth = new SMTPAuthenticator(props.getProperty("username"), props.getProperty("password"));


    if ("true".equals(smtp.getSmtpAuth())) {
        mailSession = Session.getDefaultInstance(props, auth);
    } else {
        mailSession = Session.getDefaultInstance(props);
    }


}

class SMTPAuthenticator extends Authenticator {

    private String username, password;

    public SMTPAuthenticator(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password);
    }
}
2

2 Answers

4
votes

Here is working code for sending an email with GMX:

public static void sendGMX() throws MessagingException
{
    String sender = "my.email@gmx.de";
    String password = "my.password";
    String receiver = "my-receiver@gmail.com";

    Properties properties = new Properties();

    properties.put("mail.transport.protocol", "smtp");
    properties.put("mail.smtp.host", "mail.gmx.net");
    properties.put("mail.smtp.port", "587");
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.user", sender);
    properties.put("mail.smtp.password", password);
    properties.put("mail.smtp.starttls.enable", "true");

    Session mailSession = Session.getInstance(properties, new Authenticator()
    {
        @Override
        protected PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication(properties.getProperty("mail.smtp.user"),
                    properties.getProperty("mail.smtp.password"));
        }
    });

    Message message = new MimeMessage(mailSession);
    InternetAddress addressTo = new InternetAddress(receiver);
    message.setRecipient(Message.RecipientType.TO, addressTo);
    message.setFrom(new InternetAddress(sender));
    message.setSubject("The subject");
    message.setContent("This is the message content", "text/plain");
    Transport.send(message);
}

Note

You have to manually enable POP3/IMAP support in your e-mail account otherwise you will still get an AuthenticationFailedException exception:

Exception in thread "main" javax.mail.AuthenticationFailedException: 535 Authentication credentials invalid

    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:253)
    at javax.mail.Transport.send(Transport.java:124)
0
votes

First, clean up and simplify your program by fixing these common mistakes.

Then, turn on JavaMail session debugging and examine the protocol trace. It should show you which SMTP command with which address the server is complaining about. (The property "mail.smtp.debug" is not a property JavaMail understands.)