Java 在电子邮件中附加MS Word、Excel和pdf文件

Java 在电子邮件中附加MS Word、Excel和pdf文件,java,email,email-attachments,attachment,Java,Email,Email Attachments,Attachment,下面是我发送电子邮件的代码,非常有效 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package myWorkingFiles; import org.apache.commons.mail.*; /* * * @author xyz */ public class GmailEmailWorking { public static

下面是我发送电子邮件的代码,非常有效

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package myWorkingFiles;

import org.apache.commons.mail.*;

/*
*
* @author xyz
*/
public class GmailEmailWorking {

    public static void main(String[] args) {
        String myEmailId = "myEmailId@gmail.com";
        String myPassword = "myPassword";
        String senderId = "senderId@yahoo.co.in";
        try {
            Email email = new SimpleEmail();
            email.setSmtpPort(587);
            email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword));
            email.setDebug(true);
            email.setHostName("smtp.gmail.com");
            email.setFrom(myEmailId);
            email.setSubject("Hi");
            email.setMsg("This is a test mail ... :-)");
            email.addTo(senderId);
            email.setTLS(true);
            email.send();
            System.out.println("Mail sent!");
        } catch (Exception e) {
            System.out.println("Exception :: " + e);
        }
    }
}
现在我想发送带有附件的电子邮件,与上面显示的普通电子邮件相反

请让我知道我需要做哪些更改?我相信这很容易,但遗憾的是谷歌先生也没有帮助我

我找到了一些链接,但它们没有用


快速搜索后,我发现了这个。。

你是在尝试寻找不同的东西吗