• Post Reply Bookmark Topic Watch Topic
  • New Topic

connecting to socket to send email  RSS feed

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm modifying this guy's code to send email with image attachments:
http://www.rgagnon.com/javadetails/java-0083.html

I had to tweak things so that instead of loading the image from file we load it from a database (so I pass an array of bytes instead of a file path to the encoder class). Anyway, if you look at the code below, you can see that I'm trying to tell it what the image attachment's filename should be. However, when I receive this image in my Thunderbird email client, the attachmentName is there minus the .jpg extension I would like for it to have. That seems fine since Thunderbird knows it's a JPEG, but if the user saves it to file instead of just trying to open it with Thunderbird, they might get confused since Windows doesn't figure out what type of file it is without that extension.

I used this same technique when sending the image down from a servlet and the lines below got the browser to display the image with the extension, so why isn't it working when I'm trying to email?





Thanks!
 
Van Glass
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Content-Disposition header should have an attribute of filename="name.jpg" in order to be read properly by mail clients.

The code you are using below seems to be generating filename="name".jpg causing the .jpg to be truncated.

sendln(out, "Content-Disposition: attachment;filename=\"" + attachmentName + "\".jpg");
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh... :roll:


Thanks!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!