Creating an HTML email message |
You may create an HTML message using the HtmlEmailMessage class. An HTML message consists of both HTML and plain-text parts. The HTML part is what will be displayed to mail clients that are capable of displaying HTML messages and have this option enabled. The plain-text part is what will be displayed to mail clients that are not capable of displaying HTML or have the option to display HTML messages disabled.
Example
String text = "This is the text part"; String html = "<b>This is the HTML part</b>";
// create new HtmlEmailMessage instance and set To, From and Subject headers HtmlEmailMessage message = new HtmlEmailMessage(); message.setTo("to@domain.com"); message.setFrom("from@domain.com"); message.setSubject("Sample HTML message");
// set text part message.setTextBody(text);
// set HTML part message.setHtmlBody(html);
As shown above creating an HTML message is very similar to creating a regular email message using the EmailMessage class. As with the EmailMessage class you may send this message using the Smtp class.
See also
|