'Prepare an email message for delivery via Amazon SES.
:param Record rec: a database record from the ``email_queue`` table
:returns: ``None`` if we can\'t find an email address to send to
:returns: ``dict`` if we can find an email address to send to
We look for an email address to send to in two places:
#. the context stored in ``rec.context``, and then
#. ``participant.email_address``.'

def _prepare_email_message_for_ses(self, rec):

    to = Participant.from_id(rec.participant)
    spt = self._email_templates[rec.spt_name]
    context = pickle.loads(rec.context)
    context[u'participant'] = to
    context[u'username'] = to.username
    context[u'button_style'] = u'color:    #fff;    text-decoration:none;    display:inline-block;    padding:    0    15px;    background:    #396;    white-space:    nowrap;    font:    normal    14px/40px    Arial,    sans-serif;    border-radius:    3px'
    context.setdefault(u'include_unsubscribe', True)
    email = context.setdefault(u'email', to.email_address)
    if (not email):
        return None
    langs = i18n.parse_accept_lang((to.email_lang or u'en'))
    locale = i18n.match_lang(langs)
    i18n.add_helpers_to_context(self.tell_sentry, context, locale)
    context[u'escape'] = (lambda s: s)
    context_html = dict(context)
    i18n.add_helpers_to_context(self.tell_sentry, context_html, locale)
    context_html[u'escape'] = htmlescape
    base_spt = self._email_templates[u'base']
    def render(t, context):
        b = base_spt[t].render(context).strip()
        return b.replace(u'$body', spt[t].render(context).strip())
    message = {}
    message[u'Source'] = u'Gratipay    Support    <support@gratipay.com>'
    message[u'Destination'] = {}
    message[u'Destination'][u'ToAddresses'] = [(u'%s    <%s>' % (to.username, email))]
    message[u'Message'] = {}
    message[u'Message'][u'Subject'] = {}
    message[u'Message'][u'Subject'][u'Data'] = spt[u'subject'].render(context).strip()
    message[u'Message'][u'Body'] = {u'Text': {u'Data': render(u'text/plain', context)}, u'Html': {u'Data': render(u'text/html', context_html)}}
    return message
