• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail: Problem adding attachment to email: attachment content shows in bodytext

 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All. I am trying to attach a csv file to an email. However no matter what I try it is recieved with the file contents in the email body. Any Idea how I can get this to arrive as an email attachment?

My code is as follows:


The email is receieved like this:-


------=_Part_2_15995128.1272528614964
Content-Type: application/octet-stream; name=stats.csv
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=stats.csv

contents of csv file show here (removed for posting to forum)

------=_Part_2_15995128.1272528614964
Content-Type: text/html; charset=ISO-8859-9
Content-Transfer-Encoding: 7bit

Attached Are the statistics from one of the web servers
------=_Part_2_15995128.1272528614964--
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In emails, everything is included as plain text in the body. Binary attachments are converted to Base64 before they are added. That email does not look special or strange to me.

If your email client has problems with this email, try reversing the two body parts. I've never seen an email where the attachments come before the text body before so maybe that's the problem.
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I switched the body parts round as suggested and that did not help. The email client is MS outlook. I have also tried it with my web host's webmail and that does the same thing. Any other ideas?
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Wa wrote:

Remove that line. This makes the client think that the multipart is actually plain text. The "msg.setContent( mp );" call sets the message's content type.
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, That worked! - it was of course because i was setting the whole email to be plain text
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!