package com.ismiler.jHome.mail;import java.util.HashSet;
import java.util.Set;import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;public class Server {
private static String host;
private static String userName;
private static String password;
private static String from;
private static String me;
private static String charset; static {
host = "stmp.sina.com";
userName = "8612304";
password = "xxxxxx";
from = "[email protected]";
me = "新新家园";
charset = "UTF-8";
}
public static boolean send(Set<String> target, String content) {
HtmlEmail hmal = new HtmlEmail();
hmal.setHostName(host);
hmal.setSmtpPort(25);
hmal.setAuthentication(userName, password);
try {
hmal.setFrom(from, me, charset);
hmal.setTo(target);
hmal.send();
} catch (EmailException e) {
e.printStackTrace();
return false;
}
return true;
}
public static void main(String[] args) {
Set<String> me2 = new HashSet<String>();
me2.add("[email protected]");
Server.send(me2, "<html><body>谢谢你</body></html>");
}
}这样写的话报错
Exception in thread "main" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.toArray(Unknown Source)
at org.apache.commons.mail.Email.toInternetAddressArray(Email.java:1378)
at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1154)
at org.apache.commons.mail.MultiPartEmail.buildMimeMessage(MultiPartEmail.java:254)
at org.apache.commons.mail.HtmlEmail.buildMimeMessage(HtmlEmail.java:513)
at org.apache.commons.mail.Email.send(Email.java:1266)
at com.ismiler.jHome.mail.Server.send(Server.java:35)
at com.ismiler.jHome.mail.Server.main(Server.java:46)
初次使用,请大侠指点迷经
解决方案 »
- SSH集成删除对象级联错误
- 验证URL是否真实有效
- 关于Session Bean 生命周期中的 @Init 注释
- java编程程序一个小问题
- 为什么我的HQL查不出结果?
- 原来一切正常,但是自从在SQL数据库里加了一个触发器后,就报错了,搞不懂???
- weblogic8.1配置连接池问题
- struts高手进-------(二)
- EJB中得到的Collection,如何得到它的元素.....在線等待..........
- 学j2ee,先不学java中的swing,事件处理这几章可不可以.
- 求MyEclipse6.0.1 GA+WebLogic8.1开发EJB的例子
- strsts2.1.8 多文件上传
throws EmailException Set a list of "TO" addresses. All elements in the specified Collection are expected to be of type java.mail.internet.InternetAddress. 看看API吧, 人家希望collection里面存的是InternetAddress而不是String