关于javamail的小问题,解决力送100分!!!(jar打包问题的分已结) 我看了javamail的DEMO,但还是不明白,请指点呀 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.csdn.net/expert/TopicView.asp?id=92577 props.put("mail.smtp.auth", "true"); Transport transport = session.getTransport("smtp");transport.connect(host, username, password); skyyoung(路人甲):knightmiao(): 我加上了props.put("mail.smtp.auth", "true"); Transport transport = session.getTransport("smtp");transport.connect(host, username, password);但还是报错呀???Mail: try to send mails...username: supershotpassword: abdedajavax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.AuthenticationFailedException java.lang.Throwable(java.lang.String) java.lang.Exception(java.lang.String) javax.mail.MessagingException(java.lang.String, java.lang.Exception) javax.mail.SendFailedException(java.lang.String, java.lang.Exception, javax.mail.Address [], javax.mail.Address [], javax.mail.Address []) void javax.mail.Transport.send0(javax.mail.Message, javax.mail.Address []) void javax.mail.Transport.send(javax.mail.Message) boolean com.eastpro.hkisc.util.HtmlMail.send() boolean com.eastpro.hkisc.bizlogic.GBMailBean.sendOneMail(com.eastpro.hkisc.bizlogic.MailDetail) void com.eastpro.hkisc.bizlogic.GBMailBean.sendAllMail() void com.eastpro.hkisc.bizlogic.GBMailPostMan.run()fail sending to [email protected] AuthenticationFailedException证明你的认证错误,检查用户和密码 skyyoung(路人甲):我检查了N遍,换了N个邮箱,163,263,21cn,sohu,等等,都不行,我写的用户名,密码都是对的呀,我都能进邮箱???你们怎么可以呢?你用的是哪个版本的javamail? 这个是已经通过的. public void sendMail(){ String to ="[email protected]"; String from ="[email protected]"; String server="smtp.163.net"; String user="xxx"; String password="xxxxxxx"; try{ Properties props=new Properties (); props.put("mail.smtp.host",server); props.put("mail.smtp.auth","true"); props.put("mail.bebug","true"); //URLName urlName=new URLName(server); //PasswordAuthentication pa=new PasswordAuthentication(user,password); Session sendMailSession=Session.getDefaultInstance(props,null); sendMailSession.setDebug(true); //sendMailSession.setPasswordAuthentication (urlName,pa); //SMTPTransport transport=new SMTPTransport(sendMailSession,null); Transport transport=sendMailSession.getTransport("smtp"); Message msg = new MimeMessage(sendMailSession); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = {new InternetAddress(to)}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject("Java Mail Test"); msg.setHeader("X-Mailer", "msgsend"); msg.setSentDate(new Date()); //msg.setText ("Lalalala......"); MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText("Lalalala......."); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource("c://msdos.sys"); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); transport.connect (server,user,password); //transport.connect (); transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO)); } catch(Exception ex){ ex.printStackTrace(); } } wolfsquare(狼平方):这个例子成功了,非常感激呀,我马上给分!!! 让线程里一段代码重复执行 各位大哥大姐叔叔阿姨都来说说啊 Ftp同步工具编写? 菜鸟求解高手解答,急急急!!!! 我的java程序提示无法访问的语句 求各数据库的驱动jar包的官方下载地址 在Applet上是否可以显示提示对话框 请教一个界面分布问题? 菜鸟提问:关于package和import的一个问题 学习Java用什么开发工具来练手!(目前较流行的)马上结贴 鼠标拖曳操作的问题 about ibm visualage3.0的问题
transport.connect(host, username, password);
knightmiao(): 我加上了props.put("mail.smtp.auth", "true");
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);但还是报错呀???Mail: try to send mails...
username: supershot
password: abdeda
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.AuthenticationFailedException
java.lang.Throwable(java.lang.String)
java.lang.Exception(java.lang.String)
javax.mail.MessagingException(java.lang.String, java.lang.Exception)
javax.mail.SendFailedException(java.lang.String, java.lang.Exception, javax.mail.Address [], javax.mail.Address [], javax.mail.Address [])
void javax.mail.Transport.send0(javax.mail.Message, javax.mail.Address [])
void javax.mail.Transport.send(javax.mail.Message)
boolean com.eastpro.hkisc.util.HtmlMail.send()
boolean com.eastpro.hkisc.bizlogic.GBMailBean.sendOneMail(com.eastpro.hkisc.bizlogic.MailDetail)
void com.eastpro.hkisc.bizlogic.GBMailBean.sendAllMail()
void com.eastpro.hkisc.bizlogic.GBMailPostMan.run()fail sending to [email protected]
证明你的认证错误,检查用户和密码
我检查了N遍,换了N个邮箱,163,263,21cn,sohu,等等,都不行,我写的用户名,密码都是对的呀,我都能进邮箱???
你们怎么可以呢?你用的是哪个版本的javamail?
String to ="[email protected]";
String from ="[email protected]";
String server="smtp.163.net";
String user="xxx";
String password="xxxxxxx";
try{
Properties props=new Properties ();
props.put("mail.smtp.host",server);
props.put("mail.smtp.auth","true");
props.put("mail.bebug","true"); //URLName urlName=new URLName(server);
//PasswordAuthentication pa=new PasswordAuthentication(user,password);
Session sendMailSession=Session.getDefaultInstance(props,null);
sendMailSession.setDebug(true); //sendMailSession.setPasswordAuthentication (urlName,pa);
//SMTPTransport transport=new SMTPTransport(sendMailSession,null);
Transport transport=sendMailSession.getTransport("smtp");
Message msg = new MimeMessage(sendMailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Java Mail Test");
msg.setHeader("X-Mailer", "msgsend");
msg.setSentDate(new Date());
//msg.setText ("Lalalala......"); MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText("Lalalala......."); // create the second message part
MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message
FileDataSource fds = new FileDataSource("c://msdos.sys");
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName()); // create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2); // add the Multipart to the message
msg.setContent(mp); transport.connect (server,user,password);
//transport.connect ();
transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO));
}
catch(Exception ex){
ex.printStackTrace();
}
}