This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Sending mail with attachment using HTMLEMAIL

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I am trying to send email with attachment using apache's HTMLEMAIL but the mail is always sent without attachment.. Below is the code of it



Then i found in apache's site for an example and changed my above code like

if (content != null && templateType.equalsIgnoreCase(IMailConstants.TEMPLATE_TYPE_TEXT)) {

email.setMsg(content);

} else if (content != null && templateType.equalsIgnoreCase(IMailConstants.TEMPLATE_TYPE_HTML)) {

email.setHtmlMsg(content);

}
EmailAttachment e=new EmailAttachment();
e.setDisposition(EmailAttachment.ATTACHMENT);
//e.setDescription(desc)(desc)
e.setPath("c:/Will_license.txt");

e.setDescription("A picture");

e.setName("Thingy.txt");
email.attach(e);
email.send()

but this code send my body content also as an attachment.. can some on help me to resolve this. Any help in this would be highly appreciated..


thanks
 
jeff rusty
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one help me on this?
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jeff,
I went through the apache's api for attachment--

http://commons.apache.org/email/api-1.0/org/apache/commons/mail/EmailAttachment.html#setPath(java.lang.String)

Here it is given that EmailAttachment should used by MultiPartEmail.

Hence after setting body content create object of MultiPartEmail, on that do the attachment stuff.

Thanks,
Tanzy.
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this one--



Thanks,
Tanzy.
 
jeff rusty
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Tanzy,

Thanks a lot for replying.

Yes i haved also looked it and implemented but i wonder why was it not possible with HTMLEMAIL? it also support attach correct? is it specified in apache's site that it is not possible to attach files and at the same time to display body content with HTMLEMAIL?

i was able to atachfile in HtmEmail using the below code but then the body content/HtmlMessage was also sent as attachment in that case..

please let me know.
thanks>
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jeff,

Yes, You can send attacment with body content.
That is why i wrote the code for the same in previuos post.

If it was not possible to send the attachment with body content as well then what would
be the use of creating this api.


Well i am curious to know that why are you using apaches for sending mail.

Can't you use the simple java mail api?

I have implemented the for the same using java mail api.
It's work fine for me.


Thanks,
Tanzy.
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may follow this
for using MultiPartEmail which is used to send mail with body and attachment.


Thanks,
Tanzy.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!