• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic