如何使用公共邮件1.3将图像嵌入体内

时间:2013-03-28 20:47:16

标签: java html email sendmail apache-commons

这里是我的代码附加和发送图像,但我想加载图像形式本地驱动器并将其嵌入邮件正文而无需附加请帮助我,我搜索仍然没有解决方案。 谢谢     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...");







     }





}

1 个答案:

答案 0 :(得分:3)

我没有使用过这个设施,但经过一些研究后:here's链接到一些例子。另外,请参阅org.apache.commons.mail.HtmlEmail.embed(String url, String name) 2

的文档

你打电话就像

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