Sending email with attachement and text content gives weird results.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Peter_Maier
Posted On:   Tuesday, October 9, 2001 02:50 AM

When is send an email with some text in the email body and an additional attachment i get weird results. The email is sent with the example code from the tutorial: ... Message msg = new MimeMessage(session); msg.setRecipients(Message.RecipientType.TO, internetAddresses(to)); msg.setSubject(subject); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(content); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(filename); messageBodyPart.setDataHandler(new DataHandler(source   More>>

When is send an email with some text in the email body and an

additional attachment i get weird results. The email is sent with

the example code from the tutorial:

...

Message msg = new MimeMessage(session);

msg.setRecipients(Message.RecipientType.TO, internetAddresses(to));

msg.setSubject(subject);

BodyPart messageBodyPart = new MimeBodyPart();

messageBodyPart.setText(content);

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(filename);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName(filename);

multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);

transport.sendMessage(msg, msg.getAllRecipients());

...


If this code gets run with content = "My content" and filename

poiting to a file with content "My attachement." i read the following

mail in Outlook:



--4385343.1002617471427.JavaMail.Maier_Pe.dedorath_j2



My content

--4385343.1002617471427.JavaMail.Maier_Pe.dedorath_j2
Content-Disposition: attachment; filename="d:/great_app/Classes/email.txt"



My attachement.

--4385343.1002617471427.JavaMail.Maier_Pe.dedorath_j2--



What is the reason for that? It seems as if the client cannot recognize

the fact that it is a multipart message and what the parts are.



Thanks in advance



Peter

   <<Less

Re: Sending email with attachement and text content gives weird results.

Posted By:   David_McCarthy  
Posted On:   Thursday, November 15, 2001 07:57 AM

Before you send the message, try doing a msg.saveChanges() to update the headers. Alternatively use Transport.send rather than Transport.sendMessage
About | Sitemap | Contact