Created
January 12, 2016 23:56
-
-
Save lucafaggianelli/6af7a389a9736a9dc0e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import requests | |
import logging | |
from jinja2 import Template | |
template = None | |
html = None | |
URL = "https://api.mailgun.net/v3/sandbox4a7ba08a09ec40b4a668b550607547a8.mailgun.org/messages" | |
KEY = "key-ed60f4288cb8b9c15d876ad2ae06c545" | |
recipients = [ | |
'luca.faggianelli@gmail.com', | |
'luca.faggianelli@datalogic.com' | |
] | |
def send_mail(release, link, attachments=None): | |
with open('build-done-template.html', 'r') as f: | |
template = Template(f.read()) | |
html = template.render(release=release, download=link) | |
#with open('rendered.html', 'w') as f: | |
# f.write(html) | |
if attachments: | |
files = [] | |
for att in attachments: | |
files.append( ('attachment', open(att, 'r')) ) | |
else: | |
files = None | |
r = requests.post(URL, | |
auth=('api', KEY), | |
data={ | |
'from': 'Jenkins Bot <jenkins@build.mobile.dl.net>', | |
'to': recipients, | |
'subject': 'DL-40 Android release %s' % release, | |
'html': html, | |
}, | |
files=files | |
) | |
print r | |
print r.text | |
if __name__ == '__main__': | |
if len(sys.argv) < 3: | |
exit('Usage: %s 0.0.30 http://download-link.com attach_1.pdf ... attach_N.pdf' % sys.argv[0]) | |
logging.basicConfig() | |
logging.getLogger().setLevel(logging.DEBUG) | |
release = sys.argv[1] | |
link = sys.argv[2] | |
if len(sys.argv) > 3: | |
attachment = sys.argv[3:] | |
send_mail(release, link, attachment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment