dcsimg
Sun's example to send attachment with java mail doesn't work.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ivan_siviero
Posted On:   Tuesday, April 16, 2002 03:09 AM

Hi everyone. I know maybe i am missing something.Hope everyone could help me somehow. This is the code i use to send an attachment from JavaMail. Let's suppose both smtp server and subject and addresses are ok and the file name exists on the filesystem. MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText("this is the text"); MimeBodyPart mbp2 = new MimeBodyPart(); FileDataSource fds=new FileDataSource("absolutePathToFile"); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName("myFileName"); Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1);    More>>

Hi everyone.

I know maybe i am missing something.Hope everyone could help me somehow.

This is the code i use to send an attachment from JavaMail.

Let's suppose both smtp server and subject and addresses are ok and the file name exists on the filesystem.



MimeBodyPart mbp1 = new MimeBodyPart();

mbp1.setText("this is the text");



MimeBodyPart mbp2 = new MimeBodyPart();

FileDataSource fds=new FileDataSource("absolutePathToFile");

mbp2.setDataHandler(new DataHandler(fds));

mbp2.setFileName("myFileName");



Multipart mp = new MimeMultipart();

mp.addBodyPart(mbp1);

mp.addBodyPart(mbp2);



msg.setContent(mp);

Transport.send(msg);



The message comes to my email box with only the subject and sender's email filled.

Neither the body message nor the attachment are sent.

This example is taken from the Sun's website.

Any ideas?

Ivan.

   <<Less

Re: Sun's example to send attachment with java mail doesn't work.

Posted By:   Makesh_Rao  
Posted On:   Friday, April 19, 2002 01:53 PM

Ivan


It works perfect for me. I copied the code that you sent above, and out in the code for creating a session, message and setting the addresses to it.

I had some trouble getting the content type of the message right when I first used JavaMail. doing a
message.saveChanges();


worked for me. Try doing the same.


Makesh
About | Sitemap | Contact