def test_send_email_not_verified(ses_client):
    aws_ses_client = AwsSesClient(region='eu-west-1')
    source = "*****@*****.**"
    to_address = "*****@*****.**"
    subject = "Email subject"
    body = "Email body"
    try:
        message_id = aws_ses_client.send_email(source, to_address, subject, body)
    except AwsSesClientException as e:
        assert 'Did not have authority to send from email [email protected]' in str(e)
def test_send_email(ses_client):
    aws_ses_client = AwsSesClient(region='eu-west-1')
    source = "*****@*****.**"
    to_address = "*****@*****.**"
    subject = "Email subject"
    body = "Email body"
    # All source email addresses have to be verified before you
    # can send on behalf of them.
    ses_client.verify_email_identity(EmailAddress=source)
    message_id = aws_ses_client.send_email(source, to_address, subject, body)
    assert message_id
def process_all_queues(config, queue_name_prefix):
    """
    For each queue on the aws account process one message.
    """
    logger = _set_up_logger(config)
    twilio_client = TwilioClient(config)
    aws_ses_client = AwsSesClient(region=config['AWS_REGION'])
    notify_beta_client = ApiClient(
        base_url=config['API_HOST_NAME'],
        client_id=config['DELIVERY_CLIENT_USER_NAME'],
        secret=config['DELIVERY_CLIENT_SECRET'])
    queues = _get_all_queues(config, queue_name_prefix)
    for queue in queues:
        try:
            messages = queue.receive_messages(
                MaxNumberOfMessages=config['PROCESSOR_MAX_NUMBER_OF_MESSAGES'],
                VisibilityTimeout=config['PROCESSOR_VISIBILITY_TIMEOUT'],
                MessageAttributeNames=config['NOTIFICATION_ATTRIBUTES'])
            for message in messages:
                logger.info("Processing message {}".format(
                    _get_message_id(message)))
                to_delete = True
                try:
                    _process_message(config, message, twilio_client,
                                     aws_ses_client, notify_beta_client)
                except ProcessingError as e:
                    msg = ("Failed prcessing message from queue {}."
                           " The message will not be returned to the queue."
                           ).format(queue.url)
                    logger.error(msg)
                    logger.exception(e)
                    to_delete = True
                except ExternalConnectionError as e:
                    msg = (
                        "Failed prcessing message from queue {}."
                        " The message will be returned to the queue.").format(
                            queue.url)
                    logger.error(msg)
                    logger.exception(e)
                    to_delete = False
                if to_delete:
                    message.delete()
                    logger.info("Deleted message {}".format(
                        _get_message_id(message)))
        except Exception as e:
            logger.error(
                "Unexpected exception processing message from queue {}".format(
                    queue.url))
            logger.exception(e)