• 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
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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--
 
Sheriff
Posts: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Do you pee on your compost? Does this tiny ad?
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!