以下是我发送电子邮件的代码。
/*
* 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);
}
}
}
现在我想发送附带附件的电子邮件,与上面显示的普通电子邮件相反。
请告诉我需要做哪些更改?我相信它很简单,但遗憾的是谷歌先生也没有帮助我。
我找到了一些链接,但它们没用。