javax.mail.internet.AddressException: 字符串 ``'' 中的非法地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22577914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:36:57  来源:igfitidea点击:

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

javaemail

提问by Dipesh Raichana

i m new here..

我是新来的..

i m trying to send username and password to user's email id but it showing me an error about address which i have checked but its correct.

我试图将用户名和密码发送到用户的电子邮件 ID,但它向我显示了一个关于地址的错误,我已经检查过但它是正确的。

here is my emailutility code:

这是我的电子邮件实用程序代码:

      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);

and this is my emailsending servlet code:

这是我的电子邮件发送 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) ;

and showing me the following error:

并向我展示以下错误:

   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)

采纳答案by Dipesh Raichana

i was making a mistake in giving the address .

我在提供地址时犯了一个错误。

i was using two objects and i left blank for another object.

我使用了两个对象,另一个对象留空object

this was my one object.check the updated

这是我的。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);

回答by lreeder

Your toAddress or username ('from' address), or both, is an empty string. You need to use a real email address there. Look at the value used in line 50 of EmailUtility.java and make sure it is not empty.

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

回答by jerome

Is the smtp host set up? I got this error when I had forgotten to set one in my configuration

smtp主机设置了吗?当我忘记在我的配置中设置一个时,我收到了这个错误

回答by Sergey Vlasov

I have the same error. In my case issue was with empty email address. So it was not null, but just empty string with length=0. I've added additional validation to resolve this issue.

我有同样的错误。就我而言,问题是电子邮件地址为空。所以它不是空的,而是长度为 0 的空字符串。我添加了额外的验证来解决这个问题。

回答by lpkej

In my case when I got this error, I had ccmail address left blank in server.properties file. So, make sure addresses values exists and they're valid.

在我遇到此错误的情况下,我cc在 server.properties 文件中将邮件地址留空。因此,请确保地址值存在且有效。