Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

email

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.

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:

     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)
like image 667
Dipesh Raichana Avatar asked Mar 22 '14 12:03

Dipesh Raichana


1 Answers

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.

like image 58
lreeder Avatar answered Nov 10 '22 06:11

lreeder