0

I've been looking at the network chatter between a Sample JavaMail send and several mail servers and have found that it does some extra chatter. The code sample can be found on the internet too

package example;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Sender {
    public static void main(String[] args) {
        Properties props = new Properties();
        //props.put("mail.smtp.host", "localhost");     // local james 
        props.put("mail.smtp.port", "25");
        props.put("mail.smtp.from", "misterunsub@localhost");
        props.put("mail.smtp.sendpartial", "false");
        props.put("mail.smtp.ehlo", "false");
        props.put("mail.debug", "true");

        Session session = Session.getInstance(props,null);

        try {
            Message message = new MimeMessage(session);
            //message.setFrom(new InternetAddress("misterunsub@localhost"));
            message.addHeader("List-Unsubscribe", "<mailto:list-manager@localhost?subject=Unsubscribe>");
            message.setSubject("Fancy mail from Unsub");
            message.setText("Dear Mail Crawler,"
                + "\n\nNo spam to my email, please!");
            message.saveChanges();
            InternetAddress[] alice = InternetAddress.parse("alice@localhost");
            Transport t = session.getTransport("smtp");
            t.connect();
            t.sendMessage(message, alice);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}

I've setup James on my localhost to receive the traffic. (note james uses JavaMail to send/forward mail too, but the issue is related to JavaMail), James delegates sending to JavaMail. and thus exhibits the problem too. but the Sample above is sufficient to prove what i see.

the traffic looks like this in wireshark somewhat

    >> HELO localhost  
    << 250 localhost Hello localhost (127.0.0.1 [127.0.0.1])  
    >> MAIL FROM:<misterunsub@localhost>  
    << 250 2.1.0 Sender <misterunsub@localhost> OK  
    >> RCPT TO:<alice@localhost>  
    << 250 2.1.5 Recipient <alice@localhost> OK  
    >> RSET  
    << 250 2.0.0 OK  
    >> RSET  
    << 250 2.0.0 OK  
    >> MAIL FROM:<misterunsub@localhost>  
    << 250 2.1.0 Sender <misterunsub@localhost> OK  
    >> RCPT TO:<alice@localhost>  
    << 250 2.1.5 Recipient <alice@localhost> OK  
    >> DATA  
    << 354 ok send data ending with <CRLF>.<CRLF>  
    >> this is data  
    >> .  
    << 250 2.6.0 Message recieved  
    >> QUIT  
    << 221 2.0.0 localhost Service closing transmission channel  

The oddity of the communication is the first 'MAIL FROM:', 'RCPT TO:', 'RSET' and 'RSET' especially the RSET RSET which causes a bunch of overhead.

Does anybody know how to avoid this? can anybody confirm this behavior?


Update The issue appears to be related to vpn usage or loopback/localhost communication on windows. Linux doesn't have this issue at all. Bill Shannon suggests an anti-virus or firewall, it very well might be that. since the anti-virus does notice the traffic.

Thanks Bill for your prompt replies.

4

1 に答える 1

0

このような場合、JavaMail は RSET を発行すべきではありません。JavaMail のどのバージョンを使用していますか? JavaMail からのデバッグ出力は何を示していますか?

于 2013-02-05T18:58:19.243 に答える