Hi,

you need to specify a DataSourceUrlResolver for your HtmlEmail instance
when embedding images by URL.

See the example in ther userguide (
http://commons.apache.org/proper/commons-email/userguide.html).
I just realized that the example in the userguide is outdated, instead of
the DataSourceResolverImpl, use a DataSourceUrlResolver.

The baseURL does not matter if you use absolute urls.

Thomas

On Thu, Apr 23, 2015 at 9:59 AM, Nweike Onwuyali <[email protected]>
wrote:

> Hi,
> I am a newbie and started using commons email only a few days ago.I am able
> to send mail with html content successfully. But when i tried to embed an
> image like a logo, i get the following error
> ++++++++++++++++++++++++++++++++++++++++++++++
> java.lang.NullPointerException
>
> org.apache.commons.mail.ImageHtmlEmail.replacePattern(ImageHtmlEmail.java:151)
> [error] play - Cannot invoke the action, eventually got an error:
> java.lang.Exception: java.lang.NullPointerException
> at
>
> org.apache.commons.mail.ImageHtmlEmail.buildMimeMessage(ImageHtmlEmail.java:105)
> at org.apache.commons.mail.Email.send(Email.java:1436)
> at utils.Mailer.sendMail(Mailer.java:65)
> at controllers.Users.save(Users.java:64)
> ++++++++++++++++++++++++++++++++++++++++++++++
> Below is my code:
>
> HtmlEmail email = new ImageHtmlEmail();
>
> URL logoURL = new URL(mailDetails.get("logoURL").toString());
> String cidlogo = email.embed(logoURL, "Ziphii logo");
> email.setHtmlMsg("<html>The apache logo - <img
> src=\"cid:"+cidlogo+"\"></html>");
>
> String[] to = (String[]) mailDetails.get("recipient");
> String[] from = (String[]) mailDetails.get("from");
> String[] credentials = (String[]) mailDetails.get("credentials");
>
> email.setHostName(mailDetails.get("hostName").toString());
>
> email.setSmtpPort(Integer.parseInt(mailDetails.get("hostPort").toString()));//587
> email.setAuthentication(credentials[0], credentials[1]);
>
> email.addTo(to[0], to[1]);
> email.setFrom(from[0],from[1]);
> email.setSubject(mailDetails.get("subject").toString());
>
>  email.setTextMsg(mailDetails.get("alternativeRouteUrl").toString());
>  email.setDebug(true);
>  email.send();
>
> +++++++++++++++++++++++++++++++++++++++++++
>
> I am using a Play! Framework and i am in dev mode.
>

Reply via email to