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: compose, desktop, mail, mailto, native, URI
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: javamail, mail, sender
Log4j comes with an appender that will send an email when a logging event occurs. The appender class is org.apache.log4j.net.SMTPAppender and the following gives an example of its configuration
<appender name="LogEmail" class="org.apache.log4j.net.SMTPAppender">
<param name="BufferSize" value="512" />
<param name="SMTPHost" value="mail.server.com" />
<param name="From" value="myapp@server.com" />
<param name="To" value="support@server.com" />
<param name="Subject" value="Log from myapp" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%p %t %c - %m%n" />
</layout>
</appender>
written by objects
\\ tags: email, log4j, mail
Recent Comments