commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "siegfried.goeschl@it20one.com" <siegfried.goes...@it20one.com>
Subject Re: [email]-Cannot send mail embedded with image from my Play Framework
Date Thu, 23 Apr 2015 08:47:21 GMT
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 <nweikeonwuyali@gmail.com>
> 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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message