[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2453
  • Last Modified:

Java Mail API, sending mail to Mutiple Receipiant "Illegal route-addr Error "

Dear Experts ,

I am trying to send a mail to multiple recipiants. I have List of mail address in a string separted by comma.
I am creating  InternetAddress[]  using the List of mail address in the string .
Then I am using   setRecipients method to set the To address.
When I am rulling the Program I am getting   Following Error " Illegal route-addr in string ``saravana.07
@gmail.com,dilleybabu@yahoo.com''"

I am adding the code segment and COmplete error message Here

public boolean sendMail(User userObj, Message message, String content){
      try{
                     util util=new util();
                     //userObj.email Has E-mail Addresses Seperated By Comma
                       String arr[]=util.getTokens(userObj.email,",");
                       InternetAddress inetarr[]=new InternetAddress[arr.length];
                 for(int i=0;i<arr.length;i++){
                               inetarr[i]=new InternetAddress(arr[i]);
                         }

                        message.setRecipients(Message.RecipientType.TO,inetarr);
                        /*
                             We tried This approach also
                           message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(userObj.email,false));
                        */

                        MimeMultipart multipart=new MimeMultipart();

                        BodyPart msgBodyPart=new MimeBodyPart();
                        msgBodyPart.setContent(content, "text/html");

                        multipart.addBodyPart(msgBodyPart);

                        message.setContent(multipart);
                        message.setSentDate(new Date());

                        Transport.send(message);

                        return true;

                  }catch(Exception e){
                        e.printStackTrace();
                        return false;

                  }

      }//End Of The Method

protected Properties getProperties(){

            Properties props = new Properties();

            props.put("mail.smtp.starttls.enable","true");
            props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.host", adminObj.info.server[0]);
            props.put("mail.smtp.port",adminObj.info.server_port[0]+"");
            props.put("mail.debug","false");
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.quitwait", "false");
        props.put("mail.smtp.sendpartial", "true");

            return props;

      }//End Of The Method



/***********************ERROR MESSAGE ****************************/
javax.mail.internet.AddressException: Illegal route-addr in string ``saravana.07
@gmail.com,dilleybabu@yahoo.com''
        at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java
:883)
        at javax.mail.internet.InternetAddress.parse(InternetAddress.java:819)
        at javax.mail.internet.InternetAddress.parseHeader(InternetAddress.java:
580)
        at javax.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:680
)
        at javax.mail.internet.MimeMessage.getFrom(MimeMessage.java:340)
        at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:897)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
        at javax.mail.Transport.send0(Transport.java:169)
        at javax.mail.Transport.send(Transport.java:98)
        at common.application.utilities.TenderMail.sendMail(TenderMail.java:483)

        at common.application.mail.send_user_mail.__BodhiReceive(send_user_mail.
java:146)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at jdbs.BodhiServer.callStation(Unknown Source)
        at jdbs.BodhiSend.doSend(Unknown Source)
        at common.application.mail.sendmail.__BodhiReceive(sendmail.java:361)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at JumpForwarder1.callStation(JumpForwarder1.java:863)
        at JumpForwarder1.processRequest(JumpForwarder1.java:613)
        at JumpForwarder1.authenticateUserAndExecute(JumpForwarder1.java:254)
        at JumpForwarder1.doPost(JumpForwarder1.java:132)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:284)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:204)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:257)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:245)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:199)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:509)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:184)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:164)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:156)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)

        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:20
6)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:833)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:732)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:619)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:688)
        at java.lang.Thread.run(Thread.java:534)

With Thanks and Regards
BRT





0
b_rajathilagam
Asked:
b_rajathilagam
  • 2
1 Solution
 
Gibu GeorgeCTOCommented:
I think your util.getTokens() method is not properly splitting the comma separate, if u are using Java5 use userObj.email.split(",") to get a String array
0
 
b_rajathilagamAuthor Commented:
Hi
i used util.getTokens() in many function.its working fine. even i tested here, by using
System.out.println(arr[i]) in the for loop, its displaying all the address 1by 1 i have given.
0
 
Gibu GeorgeCTOCommented:
b_rajathilagam,

Try using double quotes to surrond the local part of the email i.e "saravana.07"@gmail.com like this, this is required because the RFC822 address format considers periods as lexical separators

gibu_george
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now