开发者

Authentication Failed exception - In the middle of bulk mail sending code

We have a thread program that sends bulk mail. The information like

1. To
2. Subject
Etc.

are fetched from database, mail is composed and pushed to SMTP server. One of our customer sent a bulk mail with 2390 email. After sending 40 emails, suddenly the following exception occurred

EXCEPTION
javax.mail.AuthenticationFailedException

STACKTRACE
javax.mail.Service.connect(Service.java:306)
javax.mail.Service.connect(Service.java:156)
javax.mail.Service.connect(Service.java:105)
...............
java.lang.Thread.run(Thread.java:619)

and the rest 2350 emails failed.

Why 开发者_StackOverflow社区does this occur?

Thanks for the Suggestions and Help

Ezhil

==============================================

My Code:

Session session = Session.getInstance(properties, new SMTPAuthenticator(smtpAuthenticationBean.getUserName(), smtpAuthenticationBean.getPassword()))) : (Session.getInstance(properties, null))
for each email id
{

    InternetAddress iAddress    = new InternetAddress(getFromHeader(jobListBean.getFromDisplayName(), jobListBean.getFromEmail()));
    Multipart multipart         = new MimeMultipart(); // By default, Content Type is "mixed"


    msg.setSubject(jobListBean.getSubject());
    msg.setSentDate(new Date());

    // Set Internet Headers
    msg.setHeader("Importance", priorityType);

    msg.setHeader("Disposition-Notification-To", jobListBean.getFromEmail());

    FileDataSource fds = new FileDataSource(tempAbsoluteFileName);
    MimeBodyPart htmlBodyPart = new MimeBodyPart();

    String fileContent = org.objectstyle.woproject.util.FileStringScanner.stringFromFile(new File(tempAbsoluteFileName));
    htmlBodyPart.setText(fileContent);
    multipart.addBodyPart(htmlBodyPart);

    msg.setContent(multipart);

    InternetAddress address[] = InternetAddress.parse(emailList.toString(), true);

    Transport smtpTransport = session.getTransport();
    smtpTransport.addTransportListener(this);

    smtpTransport.connect();

    smtpTransport.sendMessage(msg, address);

    smtpTransport.close();

    File file = new File(tempAbsoluteFileName);
    file.delete();
}

====================================

Yes there is a chance for smtp server to get disconnected or not respond since its thread program, i can say at max case more than 1000 mails can get pushed in to smtp server at same time.

At any cast, will smtp server throw

EXCEPTION
javax.mail.AuthenticationFailedException

STACKTRACE
javax.mail.Service.connect(Service.java:306)
javax.mail.Service.connect(Service.java:156)
javax.mail.Service.connect(Service.java:105)
...............
java.lang.Thread.run(Thread.java:619)

if it is not able to serve our request

=============

Still i need to look in to SMTP server log.

Ezhil


An AuthenticationFailedException has nothing to do with your code, it is raised when the SMTP server returns an authentication failure.

From the javadoc:

This exception is thrown when the connect method on a Store or Transport object fails due to an authentication failure (e.g., bad user name or password).

So you will need to investigate your mail server to find out why it accepts some mail but not others. One thing I can think of would be some sort of rate-limiting mechanism.


Is it the same message being sent over and over again to the mail server?

Instead of doing the for loop for each email address, you should send all the emails in one call using sendMessage. (which your code does seem to be doing)

smtpTransport.sendMessage(msg, address); 

The mail server will then take the one copy of the message and send it to multiple addresses.

May be that will prevent the rate threshold.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜