def send_messages(self, email_messages):
    'Sends one or more EmailMessage objects and returns the number of\n        email messages sent.\n        '
    if (not email_messages):
        return
    new_conn_created = self.open()
    if (not self.connection):
        return
    num_sent = 0
    source = settings.AWS_SES_RETURN_PATH
    for message in email_messages:
        if (settings.AWS_SES_CONFIGURATION_SET and ('X-SES-CONFIGURATION-SET' not in message.extra_headers)):
            if callable(settings.AWS_SES_CONFIGURATION_SET):
                message.extra_headers['X-SES-CONFIGURATION-SET'] = settings.AWS_SES_CONFIGURATION_SET(message, dkim_domain=self.dkim_domain, dkim_key=self.dkim_key, dkim_selector=self.dkim_selector, dkim_headers=self.dkim_headers)
            else:
                message.extra_headers['X-SES-CONFIGURATION-SET'] = settings.AWS_SES_CONFIGURATION_SET
        if self._throttle:
            global recent_send_times
            now = datetime.now()
            rate_limit = self.get_rate_limit()
            logger.debug("send_messages.throttle rate_limit='{}'".format(rate_limit))
            window = 2.0
            window_start = (now - timedelta(seconds=window))
            new_send_times = []
            for time in recent_send_times:
                if (time > window_start):
                    new_send_times.append(time)
            recent_send_times = new_send_times
            if (len(new_send_times) > ((rate_limit * window) * self._throttle)):
                delta = (now - new_send_times[0])
                total_seconds = ((delta.microseconds + ((delta.seconds + ((delta.days * 24) * 3600)) * (10 ** 6))) / (10 ** 6))
                delay = (window - total_seconds)
                if (delay > 0):
                    sleep(delay)
            recent_send_times.append(now)
        kwargs = dict(Source=(source or message.from_email), Destinations=message.recipients(), RawMessage={'Data': dkim_sign(message.message().as_string(), dkim_key=self.dkim_key, dkim_domain=self.dkim_domain, dkim_selector=self.dkim_selector, dkim_headers=self.dkim_headers)})
        if self.ses_source_arn:
            kwargs['SourceArn'] = self.ses_source_arn
        if self.ses_from_arn:
            kwargs['FromArn'] = self.ses_from_arn
        if self.ses_return_path_arn:
            kwargs['ReturnPathArn'] = self.ses_return_path_arn
        try:
            response = self.connection.send_raw_email(**kwargs)
            message.extra_headers['status'] = 200
            message.extra_headers['message_id'] = response['MessageId']
            message.extra_headers['request_id'] = response['ResponseMetadata']['RequestId']
            num_sent += 1
            if ('X-SES-CONFIGURATION-SET' in message.extra_headers):
                logger.debug("send_messages.sent from='{}' recipients='{}' message_id='{}' request_id='{}' ses-configuration-set='{}'".format(message.from_email, ', '.join(message.recipients()), message.extra_headers['message_id'], message.extra_headers['request_id'], message.extra_headers['X-SES-CONFIGURATION-SET']))
            else:
                logger.debug("send_messages.sent from='{}' recipients='{}' message_id='{}' request_id='{}'".format(message.from_email, ', '.join(message.recipients()), message.extra_headers['message_id'], message.extra_headers['request_id']))
        except ResponseError as err:
            error_keys = ['status', 'reason', 'body', 'request_id', 'error_code', 'error_message']
            for key in error_keys:
                message.extra_headers[key] = getattr(err, key, None)
            if (not self.fail_silently):
                raise
    if new_conn_created:
        self.close()
    return num_sent
Sends one or more EmailMessage objects and returns the number of
email messages sent.
def send_messages(self, email_messages):
    'Sends one or more EmailMessage objects and returns the number of\n        email messages sent.\n        '
    if (not email_messages):
        return
    new_conn_created = self.open()
    if (not self.connection):
        return
    num_sent = 0
    source = settings.AWS_SES_RETURN_PATH
    for message in email_messages:
        if (settings.AWS_SES_CONFIGURATION_SET and ('X-SES-CONFIGURATION-SET' not in message.extra_headers)):
            if callable(settings.AWS_SES_CONFIGURATION_SET):
                message.extra_headers['X-SES-CONFIGURATION-SET'] = settings.AWS_SES_CONFIGURATION_SET(message, dkim_domain=self.dkim_domain, dkim_key=self.dkim_key, dkim_selector=self.dkim_selector, dkim_headers=self.dkim_headers)
            else:
                message.extra_headers['X-SES-CONFIGURATION-SET'] = settings.AWS_SES_CONFIGURATION_SET
        if self._throttle:
            global recent_send_times
            now = datetime.now()
            rate_limit = self.get_rate_limit()
            logger.debug("send_messages.throttle rate_limit='{}'".format(rate_limit))
            window = 2.0
            window_start = (now - timedelta(seconds=window))
            new_send_times = []
            for time in recent_send_times:
                if (time > window_start):
                    new_send_times.append(time)
            recent_send_times = new_send_times
            if (len(new_send_times) > ((rate_limit * window) * self._throttle)):
                delta = (now - new_send_times[0])
                total_seconds = ((delta.microseconds + ((delta.seconds + ((delta.days * 24) * 3600)) * (10 ** 6))) / (10 ** 6))
                delay = (window - total_seconds)
                if (delay > 0):
                    sleep(delay)
            recent_send_times.append(now)
        kwargs = dict(Source=(source or message.from_email), Destinations=message.recipients(), RawMessage={'Data': dkim_sign(message.message().as_string(), dkim_key=self.dkim_key, dkim_domain=self.dkim_domain, dkim_selector=self.dkim_selector, dkim_headers=self.dkim_headers)})
        if self.ses_source_arn:
            kwargs['SourceArn'] = self.ses_source_arn
        if self.ses_from_arn:
            kwargs['FromArn'] = self.ses_from_arn
        if self.ses_return_path_arn:
            kwargs['ReturnPathArn'] = self.ses_return_path_arn
        try:
            response = self.connection.send_raw_email(**kwargs)
            message.extra_headers['status'] = 200
            message.extra_headers['message_id'] = response['MessageId']
            message.extra_headers['request_id'] = response['ResponseMetadata']['RequestId']
            num_sent += 1
            if ('X-SES-CONFIGURATION-SET' in message.extra_headers):
                logger.debug("send_messages.sent from='{}' recipients='{}' message_id='{}' request_id='{}' ses-configuration-set='{}'".format(message.from_email, ', '.join(message.recipients()), message.extra_headers['message_id'], message.extra_headers['request_id'], message.extra_headers['X-SES-CONFIGURATION-SET']))
            else:
                logger.debug("send_messages.sent from='{}' recipients='{}' message_id='{}' request_id='{}'".format(message.from_email, ', '.join(message.recipients()), message.extra_headers['message_id'], message.extra_headers['request_id']))
        except ResponseError as err:
            error_keys = ['status', 'reason', 'body', 'request_id', 'error_code', 'error_message']
            for key in error_keys:
                message.extra_headers[key] = getattr(err, key, None)
            if (not self.fail_silently):
                raise
    if new_conn_created:
        self.close()
    return num_sent