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!

JavaMail - SMTP aborted with javax.mail.internet.AddressException

843834Nov 4 2008 — edited Nov 4 2008
Hello to all,

I have a question concerning JavaMail (we're using version 1.4).
We receive a SPAM Mail which we want directly send forward to our clearing post office departement.
Please consider the following code snipplet (hint: aEmlFile is the relatice path value to an EML file):
        // Create properties for the Session
        Properties tProps = new Properties();
        InputStream tSource = null;
        SMTPMessage tMessage = null;
        String tError = null;
        String tClearingPb = aPostBox;
        try {
            tProps.put( "mail.smtp.host", aEmailClient.getEmailConfiguration().getHostSend() );
            // To see what is going on behind the scene
            tProps.put( "mail.debug", "false" );
        } catch ( Exception tEx ) {
            tError = "Error in getting the ldap values with the help of the email eway. Couldn't determine the SMTP host.";
            sLog.error( aHdr.setMsg( tError ) );
            throw new EaiException( tError, tEx );
        }
        // Get a session
        Session tSession = Session.getInstance( tProps );
        try {
            tSource = new FileInputStream( *aEmlFile* );
        } catch ( FileNotFoundException tEx ) {
            tError = "Couldn't find the file " + aEmlFile;
            sLog.error( aHdr.setMsg( tError ) );
            throw new EaiException( tError, tEx );
        }
        // Get a Transport object to send e-mail
        Transport tBus = null;
        try {
            tMessage = new SMTPMessage( tSession, tSource );
            tMessage.setSendPartial( true );
            tMessage.setNotifyOptions( SMTPMessage.NOTIFY_NEVER );
            InternetAddress[] tAddress = { new InternetAddress( tClearingPb, false ) };
            tBus = tSession.getTransport( "smtp" );
            tBus.connect();
            tBus.send( tMessage, tAddress );
        } catch ( NoSuchProviderException tEx ) {
            tError = "Couldn't find the transport provider for SMTP within the session. Cause: " + tEx.getMessage();
            throw new EaiException( tError, tEx );
        } catch ( AddressException tAdrEx ) {
            tError = "Couldn't create the Internet-Address depending on post-office " + tClearingPb + "\nCause: " + tAdrEx.getMessage();
            throw new EaiException( tError, tAdrEx );
        } catch ( MessagingException tMsgEx ) {
            tError = "Error in connecting to the transport bus. Cause: " + tMsgEx.getMessage();
            throw new EaiException( tError, tMsgEx );
        } finally {
           .....
Indeed it is really simple.

Now the question: If the SPAM sender contains an unproper eMail address (e.g. >>max.muster @aspamdom.org>> ; white space within email adress) the transport.send statement ends with an exception (please ignore the following spam email send address):
Caused by: javax.mail.internet.AddressException: Illegal whitespace in address in string ``TatianaMuller @ranmamail.com''
	at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:940)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:833)
How can I solve this problem? I'm not sure but I think it should be a valid email address.
How can I disable the validation of the original sender address? Important: The message should be send to our clearing post box without any manipulations.

Any help would be appreciate.

Kind regards,
Bodo Stockschlaeder
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2008
Added on Nov 4 2008
1 comment
878 views