H4SN
H4SN

Reputation: 1748

how to embed image in body using commons mail 1.3

here is my code which attach and send image but i want to load image form local drive and embed it to body of mail without attaching please help me i have searched still no solution. thanks import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.EmailAttachment; import org.apache.commons.mail.HtmlEmail;

public class img {

     public static void main(String[]args)  throws Exception {


         // Create the attachment
          EmailAttachment attachment = new EmailAttachment();
          attachment.setPath("Monthly Target AchivedDaily.gif");
          attachment.setDisposition(EmailAttachment.INLINE);
          attachment.setDescription("Monthly");
          attachment.setName("1");


            HtmlEmail he = new HtmlEmail();




               he.setSmtpPort(25);
              he.setAuthenticator(new DefaultAuthenticator("myid","mypwd"));

              he.setDebug(false);
              he.setHostName("..com");
              he.addTo("@.com","hsn");

                //email.setSSL(true);
              he.setFrom("mail", "Hassan");
              he.setSubject("tst1");
              he.attach(attachment);




              he.send();

            System.out.println("Done...");







     }





}

Upvotes: 3

Views: 3564

Answers (1)

Ladlestein
Ladlestein

Reputation: 6150

I haven't used this facility, but after a little research: here's a link to some examples. Also, see the docs for org.apache.commons.mail.HtmlEmail.embed(String url, String name)2

You'd make a call like

String id = email.embed(new URL("file://localhost/home/mydir/images/my_image.png"), "My image");

Upvotes: 3

Related Questions