Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Illegal address in string

adrinaFeb 6 2013 — edited Feb 6 2013
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2013
Added on Feb 6 2013
1 comment
4,738 views