Attachment referencing image part

Discussion in 'Software' started by jissondennis, Mar 16, 2009.

  1. jissondennis

    jissondennis

    Joined:
    Mar 3, 2009
    Messages:
    1
    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();
    }

    }
    }
    jissondennis, Mar 16, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. war_wheelan@yahoo.com
    Replies:
    0
    Views:
    389
    war_wheelan@yahoo.com
    Jan 11, 2006
  2. war_wheelan@yahoo.com
    Replies:
    0
    Views:
    337
    war_wheelan@yahoo.com
    Jan 11, 2006
  3. war_wheelan@yahoo.com
    Replies:
    5
    Views:
    1,776
    Barry Margolin
    Jan 14, 2006
  4. Pamela Fischer
    Replies:
    11
    Views:
    1,685
    pamelafiischer@yahoo.com
    Nov 23, 2005
  5. Mark-Allen Perry
    Replies:
    7
    Views:
    3,036
    Mark-Allen Perry
    Jun 15, 2005
Loading...

Share This Page