gpt4 book ai didi

javax.mail.internet.AddressException : Illegal address in string `` ''

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:21:27 26 4
gpt4 key购买 nike

我是新来的..

我正在尝试将用户名和密码发送到用户的电子邮件 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)

最佳答案

您的 toAddress 或用户名(“发件人”地址)或两者都是空字符串。您需要在那里使用真实的电子邮件地址。查看 EmailUtility.java 第 50 行中使用的值并确保它不为空。

关于javax.mail.internet.AddressException : Illegal address in string `` '',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22577914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com