如何在邮件正文中显示附加图像(公共邮件)JAVA

时间:2013-03-11 02:56:32

标签: java html email javamail apache-commons

使用此代码我可以附加和发送5张图片,但问题是它们没有显示在邮件正文/内容中我知道我可以上传它们并引用该网址但问题是我的程序中的另一个功能创建了这些图像在创作之后我想发送它们并在邮件正文中显示。

这是我的代码

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.MultiPartEmail;
import org.apache.commons.mail.SimpleEmail;
public static void Sendmail()  throws Exception {



                EmailAttachment attachment = new EmailAttachment();
                attachment.setPath("FloorDaily.PNG");
                attachment.setDisposition(EmailAttachment.ATTACHMENT);
                attachment.setDescription("Floor Count Daily");
                attachment.setName("FloorDaily");

                EmailAttachment attachment1 = new EmailAttachment();
                attachment1.setPath("Monthly Target AchivedDaily.PNG");
                attachment1.setDisposition(EmailAttachment.ATTACHMENT);
                attachment1.setDescription("Monthly Target Achived");
                attachment1.setName("Monthly Target AchivedDaily");

                EmailAttachment attachment2 = new EmailAttachment();
                attachment2.setPath("ZuhairDaily.PNG");
                attachment2.setDisposition(EmailAttachment.ATTACHMENT);
                attachment2.setDescription("Team Zuhair");
                attachment2.setName("Team Zuhair");

                EmailAttachment attachment3 = new EmailAttachment();
                attachment3.setPath("AfzalDaily.PNG");
                attachment3.setDisposition(EmailAttachment.ATTACHMENT);
                attachment3.setDescription("Team Afzal");
                attachment3.setName("Team Afzal");

                EmailAttachment attachment4 = new EmailAttachment();
                attachment4.setPath("FarazDaily.PNG");
                attachment4.setDisposition(EmailAttachment.ATTACHMENT);
                attachment4.setDescription("Team Faraz");
                attachment4.setName("Team Faraz");

                EmailAttachment attachment5 = new EmailAttachment();
                attachment5.setPath("SalahuddinDaily.PNG");
                attachment5.setDisposition(EmailAttachment.ATTACHMENT);
                attachment5.setDescription("Team Salahuddin");
                attachment5.setName("Team Salahuddin");






                MultiPartEmail email = new MultiPartEmail();
                email.setSmtpPort(587);
                email.setAuthenticator(new DefaultAuthenticator("myid@gmail.com","mypwd"));
                email.setDebug(false);
                email.setHostName("smtp.gmail.com");
                email.addTo("id@etilizepak.com", "name");
                email.addTo("id@hotmail.com", "name");
                email.setTLS(true);
                email.setSSL(true);
                email.setFrom("ralf601@gmail.com", "Hassan Shakeel");
                email.setSubject("Progress Report (Auto Generated)  "+DATE);
                email.setMsg("Following are system generated charts if an error found report @ hshakeel@etilizepak.com");



                // add the attachment
                email.attach(attachment);
                email.attach(attachment1);
                email.attach(attachment2);
                email.attach(attachment3);
                email.attach(attachment4);
                email.attach(attachment5);

                // add the attachment
               // email.attach(attachment1);


                email.send();

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








    }   

0 个答案:

没有答案