3

这是我的附加和发送图像的代码,但我想从本地驱动器加载图像并将其嵌入邮件正文而不附加请帮助我,我搜索了仍然没有解决方案。感谢导入 org.apache.commons.mail.DefaultAuthenticator;导入 org.apache.commons.mail.EmailAttachment;导入 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...");







     }





}
4

1 回答 1

3

我没有使用过这个工具,但经过一些研究:这里有一些例子的链接。另外,请参阅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");
于 2013-03-28T21:08:02.240 回答