Skip to content

Commit

Permalink
added mailing script
Browse files Browse the repository at this point in the history
  • Loading branch information
meets2tarun committed May 15, 2018
1 parent b6f7497 commit 2ecdd3d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ chroot/
*.md5
image/casper/filesystem.squash*
image/casper/vm*
.DS_Store
9 changes: 8 additions & 1 deletion .travis.yml
Expand Up @@ -31,7 +31,7 @@ before_deploy:
- cat *.iso > "/home/travis/${image_name}"

after_deploy:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./scripts/releases_maintainer.sh; fi'


notifications:
slack: fossasia:3pMkQrSogvEMfnu9aJDW2ZYC
Expand All @@ -45,3 +45,10 @@ deploy:
file: "/home/travis/${image_name}"
on:
all_branches: true

after_deploy:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./scripts/releases_maintainer.sh; fi'
- cd mail-scripts && ./mail.py

after_failure:
- cd mail-scripts && ./mail-fail.py
33 changes: 33 additions & 0 deletions mail-scripts/mail-fail.py
@@ -0,0 +1,33 @@
#! /usr/bin/env python3
import http.client
import os
import datetime
import base64

#attachment encoding
with open('../log.txt','rb') as f:
data = f.read()
f.close()

attachment = base64.b64encode(data)

conn = http.client.HTTPSConnection("api.sendgrid.com")

print (os.environ["email"])
payload = "{\"personalizations\":[{\"to\":[{\"email\":\"" + os.environ["email"] + "\"}],\"subject\":\"Your ISO is Ready\"}],\"from\":{\"email\":\"xeon.harsh@gmail.com\",\"name\":\"Meilix Generator\"},\"reply_to\":{\"email\":\"xeon.harsh@gmail.com\",\"name\":\"Meilix Generator\"},\"subject\":\"Your ISO is ready\",\"content\":[{\"type\":\"text/html\",\"value\":\"<html><p>Hi,<br>Your Build Gave error please report it to the developer<br><br>Thank You,<br>Meilix Generator Team</p></html>\"}],\"attachments\":[{\"content\":\""+str(attachment)[2:-1]+"\",\"type\":\"text/plain\",\"filename\":\"log.txt\"}]}"

print (type(payload))

authorization = "Bearer " + os.environ["mail_api_key"]

headers = {
'authorization': authorization,
'content-type': "application/json"
}

conn.request("POST", "/v3/mail/send", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
36 changes: 36 additions & 0 deletions mail-scripts/mail.py
@@ -0,0 +1,36 @@
#! /usr/bin/env python3
import http.client
import os
import datetime
import base64

#attachment encoding
with open('../log.txt','rb') as f:
data = f.read()
f.close()

attachment = base64.b64encode(data)

conn = http.client.HTTPSConnection("api.sendgrid.com")

date = datetime.datetime.now().strftime('%Y%m%d')
url = "https://github.com/fossasia/meilix/releases/download/"+os.environ["TRAVIS_TAG"]+"/meilix-i386-custom.iso"

print (os.environ["email"])
payload = "{\"personalizations\":[{\"to\":[{\"email\":\"" + os.environ["email"] + "\"}],\"subject\":\"Your ISO is Ready\"}],\"from\":{\"email\":\"xeon.harsh@gmail.com\",\"name\":\"Meilix Generator\"},\"reply_to\":{\"email\":\"xeon.harsh@gmail.com\",\"name\":\"Meilix Generator\"},\"subject\":\"Your ISO is ready\",\"content\":[{\"type\":\"text/html\",\"value\":\"<html><p>Hi,<br>Your ISO is ready<br>URL : "+url+"<br><br>Thank You,<br>Meilix Generator Team</p></html>\"}],\"attachments\":[{\"content\":\""+str(attachment)[2:-1]+"\",\"type\":\"text/plain\",\"filename\":\"log.txt\"}]}"

print (type(payload))

authorization = "Bearer " + os.environ["mail_api_key"]

headers = {
'authorization': authorization,
'content-type': "application/json"
}

conn.request("POST", "/v3/mail/send", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

0 comments on commit 2ecdd3d

Please sign in to comment.