Results 1 to 1 of 1
- 03-16-2009, 06:56 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Attachment referencing image part
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();
}
}
}
Similar Threads
-
Sending MTOM Attachment through SOAP message
By suchismitasuchi in forum Advanced JavaReplies: 0Last Post: 01-19-2009, 01:22 PM -
Referencing a collection size in JSTL
By jfputnam in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 10-08-2008, 04:02 PM -
kindly answer the queston in attachment file
By abhinav_jain09 in forum Advanced JavaReplies: 11Last Post: 09-19-2008, 04:47 PM -
[SOLVED] Referencing Variable within Loop
By Judoon_Platoon in forum Java AppletsReplies: 2Last Post: 05-22-2008, 11:54 AM -
Referencing JPanel Class
By uncopywritable in forum New To JavaReplies: 2Last Post: 08-12-2007, 01:31 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks