问题描述
如题今天做了一个发邮件的例子代码如下publicstaticvoidmain(String[]args)throwsException{SimpleEmailemail=newSimpleEmail();email.setHostName("smtp.qq.com");//Yahoo的服务器地址是:smtp.mail.yahoo.comemail.addTo("553097934@qq.com","sunxiaomiao");email.setFrom("sunlifei_bhne@163.com","木小白");email.setAuthentication("sunlifei_bhne@163.com","*******");email.setSubject("Testmessage");email.setMsg("Thisisasimpletestofcommons-email");email.send();}
运行后报错以下是错误提示Exceptioninthread"main"org.apache.commons.mail.EmailException:Sendingtheemailtothefollowingserverfailed:smtp.qq.com:25atorg.apache.commons.mail.Email.sendMimeMessage(Email.java:1138)atorg.apache.commons.mail.Email.send(Email.java:1163)atcom.test.Test.main(Test.java:117)Causedby:javax.mail.AuthenticationFailedExceptionatjavax.mail.Service.connect(Service.java:306)atjavax.mail.Service.connect(Service.java:156)atjavax.mail.Service.connect(Service.java:105)atjavax.mail.Transport.send0(Transport.java:168)atjavax.mail.Transport.send(Transport.java:98)atorg.apache.commons.mail.Email.sendMimeMessage(Email.java:1128)...2more求助如何解决
解决方案
解决方案二:
smtp.qq.com服务器问题。。。不知道你的端口25能不能用。。。
解决方案三:
引用1楼zsx841021的回复:
smtp.qq.com服务器问题。。。不知道你的端口25能不能用。。。
刚才是把邮箱服务器写反了现在这个问题解决了但是在把程序放到web项目中时出现错误Exceptioninthread"main"org.apache.commons.mail.EmailException:Sendingtheemailtothefollowingserverfailed:smtp.163.com:25atorg.apache.commons.mail.Email.sendMimeMessage(Email.java:1138)atorg.apache.commons.mail.Email.send(Email.java:1163)atcom.test.Test.main(Test.java:117)Causedby:java.lang.NoClassDefFoundError:com/sun/activation/registries/LogSupportatjavax.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:140)atjavax.activation.CommandMap.getDefaultCommandMap(CommandMap.java:61)atjavax.activation.DataHandler.getCommandMap(DataHandler.java:153)atjavax.activation.DataHandler.getDataContentHandler(DataHandler.java:611)atjavax.activation.DataHandler.writeTo(DataHandler.java:315)atjavax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:248)atjavax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1268)atjavax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2012)atjavax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1980)atjavax.mail.Transport.send(Transport.java:97)atorg.apache.commons.mail.Email.sendMimeMessage(Email.java:1128)...2more请问这个问题该如何解决呢?
解决方案四:
少包activation.jar
解决方案五:
引用3楼9441的回复:
少包activation.jar
没有这个包我引入了