javaMail,和 commons-email 错误Javax.mail.NoSuchProviderException: smtp

 

/**
 * @company:

 * @author:

 * @createtime: 2011-4-19 上午10:06:31

 * @description:

 * @version:

 */
public class SendEmail {

	public static boolean sendSimpleEmail()throws Exception{
		boolean flag = false ;
		Email email = new SimpleEmail();
		email.setHostName("smtp.gmail.com");
		email.setSmtpPort(587);
		email.setAuthenticator(new DefaultAuthenticator("username", "password"));
		email.setTLS(true);
		email.setFrom("[email protected]");
		email.setSubject("TestMail");
		email.setMsg("This is a test mail ... :-)");
		email.addTo("[email protected]");
		email.send();
		return flag;
	}
	public static void main(String[] args) {
		try {
			sendSimpleEmail();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

我用的是 commons-email-1.2 

 

邮件发送,报错了 javax.mail.NoSuchProviderException:smtp 网上查了一堆 说 tomcat myeclipse javaee5的包发送了冲突了,

 

解决办法 是 :

1)在oralce下载一个 JavaMail 包 http://www.oracle.com/technetwork/java/javamail/index-138643.html 下载JavaMail 1.4.4 

2)在 找到myeclipse环境中的javaee.jar 包,用winrar或者其他解压缩工具打开,删除mail跟activation包,因为javaee.jar中的mail与javamail冲突。 

 

 

 

 

 

你可能感兴趣的:(oracle,javaee,MyEclipse,qq,Gmail)