Skip to content

Commit 2ecdd3d

Browse files
committed
added mailing script
1 parent b6f7497 commit 2ecdd3d

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ chroot/
33
*.md5
44
image/casper/filesystem.squash*
55
image/casper/vm*
6+
.DS_Store

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ before_deploy:
3131
- cat *.iso > "/home/travis/${image_name}"
3232

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

3636
notifications:
3737
slack: fossasia:3pMkQrSogvEMfnu9aJDW2ZYC
@@ -45,3 +45,10 @@ deploy:
4545
file: "/home/travis/${image_name}"
4646
on:
4747
all_branches: true
48+
49+
after_deploy:
50+
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./scripts/releases_maintainer.sh; fi'
51+
- cd mail-scripts && ./mail.py
52+
53+
after_failure:
54+
- cd mail-scripts && ./mail-fail.py

mail-scripts/mail-fail.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/env python3
2+
import http.client
3+
import os
4+
import datetime
5+
import base64
6+
7+
#attachment encoding
8+
with open('../log.txt','rb') as f:
9+
data = f.read()
10+
f.close()
11+
12+
attachment = base64.b64encode(data)
13+
14+
conn = http.client.HTTPSConnection("api.sendgrid.com")
15+
16+
print (os.environ["email"])
17+
payload = "{\"personalizations\":[{\"to\":[{\"email\":\"" + os.environ["email"] + "\"}],\"subject\":\"Your ISO is Ready\"}],\"from\":{\"email\":\"[email protected]\",\"name\":\"Meilix Generator\"},\"reply_to\":{\"email\":\"[email protected]\",\"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\"}]}"
18+
19+
print (type(payload))
20+
21+
authorization = "Bearer " + os.environ["mail_api_key"]
22+
23+
headers = {
24+
'authorization': authorization,
25+
'content-type': "application/json"
26+
}
27+
28+
conn.request("POST", "/v3/mail/send", payload, headers)
29+
30+
res = conn.getresponse()
31+
data = res.read()
32+
33+
print(data.decode("utf-8"))

mail-scripts/mail.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#! /usr/bin/env python3
2+
import http.client
3+
import os
4+
import datetime
5+
import base64
6+
7+
#attachment encoding
8+
with open('../log.txt','rb') as f:
9+
data = f.read()
10+
f.close()
11+
12+
attachment = base64.b64encode(data)
13+
14+
conn = http.client.HTTPSConnection("api.sendgrid.com")
15+
16+
date = datetime.datetime.now().strftime('%Y%m%d')
17+
url = "https://github.com/fossasia/meilix/releases/download/"+os.environ["TRAVIS_TAG"]+"/meilix-i386-custom.iso"
18+
19+
print (os.environ["email"])
20+
payload = "{\"personalizations\":[{\"to\":[{\"email\":\"" + os.environ["email"] + "\"}],\"subject\":\"Your ISO is Ready\"}],\"from\":{\"email\":\"[email protected]\",\"name\":\"Meilix Generator\"},\"reply_to\":{\"email\":\"[email protected]\",\"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\"}]}"
21+
22+
print (type(payload))
23+
24+
authorization = "Bearer " + os.environ["mail_api_key"]
25+
26+
headers = {
27+
'authorization': authorization,
28+
'content-type': "application/json"
29+
}
30+
31+
conn.request("POST", "/v3/mail/send", payload, headers)
32+
33+
res = conn.getresponse()
34+
data = res.read()
35+
36+
print(data.decode("utf-8"))

0 commit comments

Comments
 (0)