您的位置:首页 > 食品饮料 > 休闲食品 > java编程思想java mail问题,邮件发不出去,请教高手!

java编程思想java mail问题,邮件发不出去,请教高手!

luyued 发布于 2011-02-25 18:27   浏览 N 次  
>我的程序代码如下:>>import javax.mail.internet.internetaddress;>>import javax.mail.internet.mimessage;>>import java.util.properties;>>import javax.mail.session;>>import java.io.fileoutputstream;>>import javax.activation.filedatasource;>>import javax.activation.datahandler;>>import javax.mail.internet.mimebodypart;>>import javax.mail.internet.mimultipart;>>import javax.mail.message;>>import javax.mail.transport;>>public class htmlmessagesender>>{>>string protocol = "smtp";>>string from = "lebrondomiante@sina.cn";>>string to = "这里写的是我的一个gmail账户";>>string subject = "test";>>string body = "hello!!"+>>"";>>public static void main(string[] args) throws exception>>{>>string server = "smtp.sina.com.cn";>>string user = "我的用户名";>>string pass = "我的密码";>>htmlmessagesender sender = new htmlmessagesender ();>>session session = sender.createsession();>>mimessage message = sender.createssage(session);>>transport transport = session.gettransport();>>transport.connect(server, user, pass);>>transport.sendmessage(message,message.getrecipients(message.recipienttype.to));>>transport.close();>>}>>public session createsession()>>{>>properties props = new properties();>>props.setproperty("mail.transport.protocol", protocol);>>props.setproperty("mail.smtp.auth","true");>>session session = session.getinstance(props);>>session.setdebug(true);>>return session;>>}>>public mimessage createssage(session session) throws exception>>{>>mimessage message = new mimessage(session);>>message.setfrom(new internetaddress(from));>>message.setrecipients(message.recipienttype.to, internetaddress.parse(to));>>message.setsubject(subject);>>mimultipart multipart = new mimultipart("related");>>mimebodypart htmlbodypart = new mimebodypart();>>htmlbodypart.setcontent(body, "text/html;charset=gb2312");>>multipart.addbodypart(htmlbodypart);>>mimebodypart gifbodypart = new mimebodypart();>>filedatasource fds = new filedatasource("e:\\lebron james\\images.jpg");>>gifbodypart.setdatahandler(new datahandler(fds));>>gifbodypart.setcontentid("lebron");>>multipart.addbodypart(gifbodypart);>>message.setcontent(multipart);>>message.savechanges();>>return message;>>}>>}>>然后运行后出错:>>535 #5.7.0 authentication failed>>exception in thread "main" javax.mail.authenticationfailedexception>>at javax.mail.service.connect(service.java:319)>>at javax.mail.service.connect(service.java:169)>>at htmlmessagesender.main(htmlmessagesender.java:33)>>请教高手是哪里出了问题,我现在人在澳大利亚,这个和我不在国内有关系吗?>>没有最佳答案>>认证失败,原因要具体分析。你怀疑和不在国内有关,可以用澳大利亚的邮箱系统去测试啊。要学会自己分析问题,这样才能不断提高>>认证失败>>检查一下帐号跟密码吧>

生活频道——笑谈生活,坐看人生,这里有着小人物的健康生活。

收藏到:Del.icio.us
图文资讯
广告赞助商