我是新来的..
我正在尝试将用户名和密码发送到用户的电子邮件ID,但是它显示了我已检查过的地址错误,但是它是正确的。
这是我的电子邮件代码:
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(userName));
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
这是我的电子邮件发送servlet代码:
Logic.EmailUtility.sendEmail(host, port, user, pass, email, subject,
message);
resultMessage = "The username and password has been sent successfully";
connection con = new connection();
con.getConnection();
String query = "insert into users (usertype,en_no,password) values(?,?,?)";
PreparedStatement ps = con.getConnection().prepareStatement(query) ;
并向我显示以下错误:
javax.mail.internet.AddressException: Illegal address in string ``''
at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:110)
at Logic.EmailUtility.sendEmail(EmailUtility.java:50)
at Servlet.EmailSendingServlet.doPost(EmailSendingServlet.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
答案 0 :(得分:3)
您的toAddress或用户名('from'地址)或两者都是空字符串。您需要在那里使用真实的电子邮件地址。查看EmailUtility.java第50行中使用的值,并确保它不为空。
答案 1 :(得分:1)
我在提供地址时犯了错误。
我正在使用两个对象而我留空了另一个object
。
这是我的object
。检查更新的
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(userName));
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
答案 2 :(得分:0)
是否设置了smtp主机?当我忘记在配置中设置一个
时,我收到了这个错误答案 3 :(得分:0)
我有同样的错误。在我的情况下,问题是空的电子邮件地址。所以它不是null,而只是长度为0的空字符串。 我已添加其他验证来解决此问题。
答案 4 :(得分:0)
在我遇到此错误的情况下,server.properties文件中的cc
邮件地址为空。因此,请确保地址值存在并且有效。