Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > Attachment referencing image part

Reply
Thread Tools

Attachment referencing image part

 
 
jissondennis jissondennis is offline
Junior Member
Join Date: Mar 2009
Posts: 1
 
      03-16-2009
Hi
I am using javamail-1.4.1. I have to send image in BodyPart, not attachment.Since I don't have a local file I decided to write a class that uses DataSource
in which I can pass inputstream, read from sql server database image field directly. But some times I am getting the image as attachment with the name mime.jpg as well as it can seen in body part.
Can someone please tell me where I am going wrong?
Thanks & Regards,

Jisson Dennis

public class MailService {

public static void main(String args[]){
OfficeAdminEntity officeEntity = new OfficeAdminEntity();
RcOffice rcOffice;
try {
rcOffice = officeEntity.getSignature("20125");
ResourceBundle bundle = ResourceBundle.getBundle("MessageResources");
String host=(String)bundle.getString("EMAIL_HOST_IP");

Properties props = new Properties();
props.put("mail.smtp.host", host);
Session session = Session.getInstance(props);
Multipart multipart = new MimeMultipart();
BodyPart bodypart = new MimeBodyPart();
Message msg = new MimeMessage(session);
String subject="testmail";
//Create the text bit of the body
String content="test";
bodypart.setContent(content,"text/html");
multipart.addBodyPart(bodypart);

//Create the image part of the body.

BodyPart imagePart = new MimeBodyPart();
DataSource dataSource=new ByteArrayDataSource(rcOffice.getSignature(),"image/png");
imagePart.setDataHandler(new DataHandler(dataSource));
imagePart.setHeader("Content-ID","<image>");
multipart.addBodyPart(imagePart);

InternetAddress[] address = { new InternetAddress("")};
msg.setRecipients(Message.RecipientType.TO, address);

msg.setFrom(new InternetAddress(""));
msg.setSubject(subject);
msg.setContent(multipart);

Transport.send(msg);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HMS Victory in 1:48 scale - Part 3 & Part 4 Alexander Blokhin Digital Photography 0 12-23-2009 10:11 AM
Variable displays at one part while does not in another part in a Jack ASP General 8 05-10-2005 07:26 PM
ActiveX apologetic Larry Seltzer... "Sun paid for malicious ActiveX code, and Firefox is bad, bad bad baad. please use ActiveX, it's secure and nice!" (ok, the last part is irony on my part) fernando.cassia@gmail.com Java 0 04-16-2005 10:05 PM
Referencing an Image's Map's Link's Details Lucanus Javascript 1 10-16-2003 12:30 AM
Easy part done, now the hard part!! jollyjimpoppy A+ Certification 0 09-10-2003 10:37 AM



Advertisments