Add inbox actions. Note that this isn't enabled because of issues around DKIM in Gmail with SES.
This commit is contained in:
parent
99bd16a69c
commit
87a5b17d20
2 changed files with 60 additions and 5 deletions
|
@ -4,6 +4,12 @@
|
|||
<meta name="viewport" content="width=device-width" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>{{ subject }}</title>
|
||||
|
||||
{% if action_metadata %}
|
||||
<script type="application/ld+json">
|
||||
{{ action_metadata }}
|
||||
</script>
|
||||
{% endif %}
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; margin: 0; padding: 0;"><style type="text/css">
|
||||
@media only screen and (max-width: 600px) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import traceback
|
||||
import json
|
||||
|
||||
from flask.ext.mail import Message
|
||||
|
||||
|
@ -13,7 +14,42 @@ template_env = get_template_env("emails")
|
|||
class CannotSendEmailException(Exception):
|
||||
pass
|
||||
|
||||
def send_email(recipient, subject, template_file, parameters):
|
||||
class GmailAction(object):
|
||||
""" Represents an action that can be taken in Gmail in response to the email. """
|
||||
def __init__(self, metadata):
|
||||
self.metadata = metadata
|
||||
|
||||
@staticmethod
|
||||
def confirm(name, url, description):
|
||||
return GmailAction({
|
||||
"@context": "http://schema.org",
|
||||
"@type": "EmailMessage",
|
||||
"action": {
|
||||
"@type": 'ConfirmAction',
|
||||
"name": name,
|
||||
"handler": {
|
||||
"@type": "HttpActionHandler",
|
||||
"url": get_app_url() + '/' + url
|
||||
}
|
||||
},
|
||||
"description": description
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def view(name, url, description):
|
||||
return GmailAction({
|
||||
"@context": "http://schema.org",
|
||||
"@type": "EmailMessage",
|
||||
"action": {
|
||||
"@type": 'ViewAction',
|
||||
"name": name,
|
||||
"url": get_app_url() + '/' + url
|
||||
},
|
||||
"description": description
|
||||
})
|
||||
|
||||
|
||||
def send_email(recipient, subject, template_file, parameters, action=None):
|
||||
app_title = app.config['REGISTRY_TITLE_SHORT']
|
||||
app_url = get_app_url()
|
||||
|
||||
|
@ -29,7 +65,8 @@ def send_email(recipient, subject, template_file, parameters):
|
|||
'app_logo': 'https://quay.io/static/img/quay-logo.png', # TODO: make this pull from config
|
||||
'app_url': app_url,
|
||||
'app_title': app_title,
|
||||
'app_link': app_link_handler
|
||||
'app_link': app_link_handler,
|
||||
'action_metadata': json.dumps(action.metadata) if action else None
|
||||
})
|
||||
|
||||
rendered_html = template_env.get_template(template_file + '.html').render(parameters)
|
||||
|
@ -61,20 +98,29 @@ def send_change_email(username, email, token):
|
|||
})
|
||||
|
||||
def send_confirmation_email(username, email, token):
|
||||
action = GmailAction.confirm('Confirm E-mail', 'confirm?code=' + token,
|
||||
'Verification of e-mail address')
|
||||
|
||||
send_email(email, 'Please confirm your e-mail address', 'confirmemail', {
|
||||
'username': username,
|
||||
'token': token
|
||||
})
|
||||
}, action=action)
|
||||
|
||||
def send_repo_authorization_email(namespace, repository, email, token):
|
||||
action = GmailAction.confirm('Verify E-mail', 'authrepoemail?code=' + token,
|
||||
'Verification of e-mail address')
|
||||
|
||||
subject = 'Please verify your e-mail address for repository %s/%s' % (namespace, repository)
|
||||
send_email(email, subject, 'repoauthorizeemail', {
|
||||
'namespace': namespace,
|
||||
'repository': repository,
|
||||
'token': token
|
||||
})
|
||||
}, action=action)
|
||||
|
||||
def send_recovery_email(email, token):
|
||||
action = GmailAction.view('Recover Account', 'recovery?code=' + token,
|
||||
'Recovery of an account')
|
||||
|
||||
subject = 'Account recovery'
|
||||
send_email(email, subject, 'recovery', {
|
||||
'email': email,
|
||||
|
@ -87,12 +133,15 @@ def send_payment_failed(email, username):
|
|||
})
|
||||
|
||||
def send_org_invite_email(member_name, member_email, orgname, team, adder, code):
|
||||
action = GmailAction.view('Join Team %s' % team, 'confirminvite?code=' + code,
|
||||
'Invitation to join a team')
|
||||
|
||||
send_email(member_email, 'Invitation to join team', 'teaminvite', {
|
||||
'inviter': adder,
|
||||
'token': code,
|
||||
'organization': orgname,
|
||||
'teamname': team
|
||||
})
|
||||
}, action=action)
|
||||
|
||||
|
||||
def send_invoice_email(email, contents):
|
||||
|
|
Reference in a new issue