亚马逊 ses 节流 – 超过最大发送速率

Amazon sesThrottling – Maximum sending rate exceeded

根据此 documentation 所说,如果我达到最大发送速率,我将收到错误消息。我的最大发送速率是每秒 14 封电子邮件,我尝试同时发送 100 封邮件,所有邮件都到达了收件人。

所以我想知道为什么 Amazon SES 没有发送任何 "signal" 抱怨我的过多或更容易,为什么 Amazon SES 发送了所有这 100 封电子邮件,而它应该只发送 14 封。

这是我使用的代码:

    List<String> destinations = new ArrayList<>(); //replace with your TO email addresses

    for (int i = 0; i < 100; i++) {
        destinations.add("Receiver address");
    }
    int i=0;
    for (String destination : destinations) {

        new Thread("" + i){
            public void run(){
                System.out.println("Thread: " + getName() + " running");
                int maxRetries = 10;
                while(maxRetries-->0) {
                    try {
                        // Create the subject and body of the message.
                        Content subject = new Content().withData("Asunto");
                        Content textBody = new Content().withData("cuerpo");
                        Body body = new Body().withText(textBody);

                        // Create a message with the specified subject and body.
                        Message message = new Message().withSubject(subject).withBody(body);
                        Destination destination2 = new Destination().withToAddresses(new String[]{destination});
                        // Assemble the email.
                        SendEmailRequest request = new SendEmailRequest().withSource("fromnaddres").withDestination(destination2).withMessage(message);

                        //wait for a permit to become available
                        //rateLimiter.acquire();

                        //call Amazon SES to send the message
                        SendEmailResult result = client.sendEmail(request);
                        System.out.println("sent "+result.getMessageId());
                        break;
                    } catch (AmazonServiceException e) {
                        //retries only throttling errors
                        System.out.println("hola");
                        if ("Throttling".equals(e.getErrorCode())  && "Maximum sending rate exceeded.".equals(e.getMessage())) {
                            System.out.println("Maximum send rate exceeded when sending email to "+destination+". "
                                    +(maxRetries>1?"Will retry.":"Will not retry.") );
                        } else {
                            System.out.println("Unable to send email to: "+destination+". " +e.toString());
                            break;
                        }
                    } catch(Exception e) {
                        System.out.println("Unable to send email to: "+destination+". " +e.toString());
                        break;
                    }
                }
            }
        }.start();

        i++;
    }

Amazon SES 在每日消息配额和最大发送速率方面提供了一些空间或灵活性。他们没有透露允许的偏差百分比是多少,但是您可以通过一些测试来确定。