Dec 18

If you get the following error and not sure how to fix it then read on.


Caused by: javax.mail.MessagingException: 501 Syntax: HELO hostname
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
at javax.mail.Service.connect(Service.java:248)

This is typically caused by the system property “mail.smtp.localhost” not being set by your Java VM. This should be already set for you automatically if your runtime environment is configured properly.

From the javadoc:

Local host name used in the SMTP HELO or EHLO command. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly.

Hope this helps.

written by objects \\ tags: , , , , ,

Oct 03

The Desktop class was added in Java 6 to handle launching associated applications on the native desktop.

Following shows how to launch the default mail application and open a mail composing window.

Desktop desktop = Desktop.getDesktop();
desktop.mail();

Or you can use a mailto: URI to also fill out the address field.

Desktop desktop = Desktop.getDesktop();
desktop.mail(new URI("mailto:someone@acme.com"));

written by objects \\ tags: , , , , ,

Aug 26

When specifying an email address using JavaMail you can not only specify actual email address of the person, but also their name if required. The InternetAddress class is used to represent an email address which includes support for specifying both the email address and the personal name.

There are two ways this can be done, firstly the RFC822 address syntax can be used to specify both in one string.

message.setFrom(new InternetAddress("Joe Smith <joe@acme.com>"));

Or alternatively a constructor is available to specify the two separately

message.setFrom(new InternetAddress("joe@acme.com", "Joe Smith"));

written by objects \\ tags: , ,