-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendmail.py
More file actions
51 lines (39 loc) · 1.48 KB
/
sendmail.py
File metadata and controls
51 lines (39 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
port = 465 # For SSL
password = os.environ['MAIL_PASSWORD'] # needs to be a heroku config variable
# Create a secure SSL context
context = ssl.create_default_context()
balgoEmailAddress = "balgo.trader@gmail.com"
def sendMail(traded):
print('Starting Email Summary')
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login(balgoEmailAddress, password)
sender_email = balgoEmailAddress
receiver_email = os.environ['MAIL_RECEIVER']
message = MIMEMultipart("alternative")
message["Subject"] = "bAlgo Execution Summary"
message["From"] = sender_email
message["To"] = receiver_email
executionSummary = ""
for trade in traded:
executionSummary += "<p>" + trade + ' ' + str(traded[trade]) + ' units' + "</p>"
html = """\
<html>
<body>
<p>Here is your daily bAlgo Execution Summary</p>
""" + executionSummary + """
</body>
</html>
"""
# Turn this into html MIMEText objects
part = MIMEText(html, "html")
# Add HTML part to MIMEMultipart message
# The email client will try to render the last part first
message.attach(part)
server.sendmail(sender_email, receiver_email, message.as_string())
print('Ending Email Summary')
# testing...
#sendMail()