简体   繁体   中英

Javamail rate for the client exceeded

I need to send at least 200 messages from a stretch. When the program starts, send mail successfully to 15 or 17, then I get this error:

MESSAGE ERROR:

com.sun.mail.smtp.SMTPSendFailedException: 421 4.4.2 Message submission rate for this client has exceeded the configured limit

What I can do?

CODE JAVA

public void mandarEmail(String correos, String mensaje, String asunto) {
    Message message;
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.transport.protocol", "smtp");
    props.setProperty("mail.smtp.port", "587");
    props.put("mail.smtp.host", "pod51004.outlook.com");
    props.put("mail.smtp.debug", "true");

    Session session = Session.getInstance(props, new javax.mail.Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("docemail@usmp.pe", "docpass");
        }
    });

    try {
        message = new MimeMessage(session);
        message.setFrom(new InternetAddress("USMP - FN <documentos-fn@usmp.pe>"));
        message.setSubject(asunto);
        message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(correos));
        message.addRecipients(Message.RecipientType.BCC, new InternetAddress[]{new InternetAddress("ivan_pro_nice@hotmail.com")});
        message.setContent(mensaje, "text/html; charset=utf-8");
        Transport transport = session.getTransport("smtp");
        transport.connect("docemail@usmp.pe", "docpass");
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    } finally {
        props = null;
        message = null;
    }
}

That's the server you're connecting to, and not a client issue. Here's a doc on how to parse SMTP codes from the server.

A mail server will reply to every request a client (such as your email program) makes with a return code. This code consists of three numbers.

In your case, you're getting 421 .

if you want to send single email to 200 clients. Than u can add an array of reciever's email addresses of size upto 50. but i you want to send different msg for each email. Then you can create a new connection to email server with a counter that counts send emails as well as it counts 15 it should create a new connection.

to test your code use mailtrap.io

您可能需要从邮件服务器供应商处购买一个“企业”帐户,以便他们可以发送更多电子邮件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM