|
|
@@ -3,29 +3,18 @@ import requests.exceptions
|
|
|
import base
|
|
|
import input_sources
|
|
|
import output
|
|
|
-import base
|
|
|
-
|
|
|
-_RECIPIENTS = {
|
|
|
- 'martin': 'martin@gerner.co',
|
|
|
- 'pointy': 'martin@pointy.com',
|
|
|
- 'georgina': 'georgina@pointy.com',
|
|
|
-}
|
|
|
-
|
|
|
-_MAILGUN_API_URL = 'https://api.mailgun.net/v3/mg.gerner.co'
|
|
|
-_MAILGUN_API_KEY = 'key-80245476ae35aa626d782556419280f9'
|
|
|
-_MAILGUN_SENDER_EMAIL = 'noreply@mg.gerner.co'
|
|
|
+import conf
|
|
|
|
|
|
def _send_by_sendgrid(recipient, subject, email_body):
|
|
|
- auth = ('api', _MAILGUN_API_KEY)
|
|
|
+ auth = ('api', conf.MAILGUN_API_KEY)
|
|
|
body = {
|
|
|
- 'from': _MAILGUN_SENDER_EMAIL,
|
|
|
+ 'from': conf.MAILGUN_SENDER_EMAIL,
|
|
|
'to': recipient,
|
|
|
'subject': subject,
|
|
|
'text': email_body
|
|
|
}
|
|
|
|
|
|
- resp = requests.post(_MAILGUN_API_URL + '/messages', data=body, auth=auth)
|
|
|
-
|
|
|
+ resp = requests.post(conf.MAILGUN_API_URL + '/messages', data=body, auth=auth)
|
|
|
if resp.status_code != 200:
|
|
|
resp.raise_for_status()
|
|
|
|
|
|
@@ -37,7 +26,7 @@ class Email(base.BaseService):
|
|
|
if terminator == 'done':
|
|
|
body = ' '.join(tokens)
|
|
|
try:
|
|
|
- _send_by_sendgrid(_RECIPIENTS[recipient], 'snowbody email', body)
|
|
|
+ _send_by_sendgrid(conf.MAILGUN_RECIPIENTS[recipient], 'snowbody email', body)
|
|
|
output.success()
|
|
|
except requests.exceptions.HTTPError, e:
|
|
|
output.failure(str(e))
|
|
|
@@ -47,11 +36,11 @@ class Email(base.BaseService):
|
|
|
|
|
|
def call(self):
|
|
|
output.text('Specify recipient')
|
|
|
- recipient = input_sources.get_token(preferred_phrases=_RECIPIENTS.keys())
|
|
|
- if recipient in _RECIPIENTS:
|
|
|
+ recipient = input_sources.get_token(preferred_phrases=conf.MAILGUN_RECIPIENTS.keys())
|
|
|
+ if recipient in conf.MAILGUN_RECIPIENTS:
|
|
|
self._send(recipient)
|
|
|
else:
|
|
|
output.failure('Could not find an email recipient "%s".' % recipient)
|
|
|
|
|
|
def help(self):
|
|
|
- return 'Sends email to pre-configured recipients. Available recipients: %s' % ', '.join(_RECIPIENTS.keys())
|
|
|
+ return 'Sends email to pre-configured recipients. Available recipients: %s' % ', '.join(conf.MAILGUN_RECIPIENTS.keys())
|