Hi folks,

it is also a good idea to check the existing tests :-)

There is also a a "Live Test" which allows you to send the emails to your actual SMTP server (when configured properly)

http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailLiveTest.java?revision=1628546&view=markup

Cheers,

Siegfried Goeschl

On 23.04.15 10:34, Thomas Neidhart wrote:
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.



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to