def test_send_email(to, cc, bcc):
    # Given
    hook = SESHook()
    ses_client = hook.get_conn()
    mail_from = '*****@*****.**'

    # Amazon only allows to send emails from verified addresses,
    # then we need to validate the from address before sending the email,
    # otherwise this test would raise a `botocore.errorfactory.MessageRejected` exception
    ses_client.verify_email_identity(EmailAddress=mail_from)

    # When
    response = hook.send_email(
        mail_from=mail_from,
        to=to,
        subject='subject',
        html_content='<html>Test</html>',
        cc=cc,
        bcc=bcc,
        reply_to='*****@*****.**',
        return_path='*****@*****.**',
    )

    # Then
    assert response is not None
    assert isinstance(response, dict)
    assert 'MessageId' in response
Exemple #2
0
def send_email(
    to: Union[List[str], str],
    subject: str,
    html_content: str,
    files: Optional[List] = None,
    cc: Optional[Union[List[str], str]] = None,
    bcc: Optional[Union[List[str], str]] = None,
    mime_subtype: str = 'mixed',
    mime_charset: str = 'utf-8',
    conn_id: str = 'aws_default',
    **kwargs,
) -> None:
    """Email backend for SES."""
    hook = SESHook(aws_conn_id=conn_id)
    hook.send_email(
        mail_from=None,
        to=to,
        subject=subject,
        html_content=html_content,
        files=files,
        cc=cc,
        bcc=bcc,
        mime_subtype=mime_subtype,
        mime_charset=mime_charset,
    )
def test_get_conn():
    hook = SESHook(aws_conn_id='aws_default')
    assert hook.get_conn() is not None