aspose file tools*
The moose likes Other Open Source Projects and the fly likes Sending mail with attachment using HTMLEMAIL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Sending mail with attachment using HTMLEMAIL" Watch "Sending mail with attachment using HTMLEMAIL" New topic
Author

Sending mail with attachment using HTMLEMAIL

jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
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

Joined: Nov 07, 2006
Posts: 109
Can some one help me on this?
Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
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.


Roll with punchers, there is always tomorrow.
Techie Blog -- http://jtanzy.blogspot.com/
Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
Try this one--



Thanks,
Tanzy.
jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
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

Joined: Jul 19, 2009
Posts: 110
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

Joined: Jul 19, 2009
Posts: 110
You may follow this
for using MultiPartEmail which is used to send mail with body and attachment.


Thanks,
Tanzy.
 
 
subject: Sending mail with attachment using HTMLEMAIL