use of org.apache.commons.mail.resolver.DataSourceUrlResolver in project SpringStepByStep by JavaProgrammerLB.
the class JavaMailDemo method test.
@Test
public void test() {
try {
// load your HTML email template
String htmlEmailTemplate = "....hello how are you <img src=\"http://www.apache.org/images/feather.gif\"> ....";
// define you base URL to resolve relative resource locations
URL url = new URL("http://www.apache.org");
// create the email message
ImageHtmlEmail email = new ImageHtmlEmail();
email.setDataSourceResolver(new DataSourceUrlResolver(url));
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setSSLOnConnect(true);
email.setFrom("username", "LIUBEI");
email.addTo("admin@yitianyigexiangfa.com", "ADMIN");
email.setAuthentication("username", "password");
email.setSubject("Test email with inline image");
// set the html message
email.setHtmlMsg(htmlEmailTemplate);
// set the alternative message
email.setTextMsg("Your email client does not support HTML messages");
// send the email
email.send();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (EmailException e) {
e.printStackTrace();
}
}
Aggregations