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


      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);
                  MimeMessage message = new MimeMessage(session);
                  message.setFrom(new InternetAddress(from));   // Illegal Address String
                  message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
              catch(MessagingException mex){
      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?

      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:
          And some pointers to other JavaMail tutorials: