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("tp.devtest3@ae.ey.com")};
msg.setRecipients(Message.RecipientType.TO, address);

msg.setFrom(new InternetAddress("jissontest@test.com"));
msg.setSubject(subject);
msg.setContent(multipart);

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

}
}