1 Reply Latest reply: Feb 6, 2013 9:29 PM by Bill Shannon-Oracle RSS

    Illegal address in string

    Prasad K T
      Hi Team,

      Am trying to send a email using localSMTP pro. I have verified the following link

      http://www.tutorialspoint.com/java/java_sending_email.htm

      This is my code
          public void sendmail() throws MessagingException {
              String to = new String();
              to = to;
              String from = new String();
              from = from;
              String host = "localhost";
              Properties prop = System.getProperties(); 
              prop.setProperty("mail.smtp.host", host);
              Session session = Session.getDefaultInstance(prop);
              try{
                  MimeMessage message = new MimeMessage(session);
                  message.setFrom(new InternetAddress(from));   // Illegal Address String
                  message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
                  message.setSubject(subj);
                  message.setText(txt);
                  Transport.send(message);
              }
              catch(MessagingException mex){
                  mex.printStackTrace();
              }
          }
      This is the error message which i got

      javax.mail.internet.AddressException: Illegal address in string ``''
           at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:108)
           at view.Mail.sendmail(Mail.java:67)
           at view.Mail.Send(Mail.java:79)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      Can any one pls help me?

      Regards,
      Prasad K T.
        • 1. Re: Illegal address in string
          Bill Shannon-Oracle
          I really have no idea what you're trying to accomplish with this code:

          String to = new String();
          to = to;
          String from = new String();
          from = from;

          It doesn't appear that you've set the From address at all.

          What version of JavaMail are you using?

          You might want to look at the JavaMail FAQ:
          http://www.oracle.com/technetwork/java/javamail/faq/index.html
          And some pointers to other JavaMail tutorials:
          http://www.oracle.com/technetwork/java/javamail/index-138267.html