-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_email.py
39 lines (33 loc) · 1.35 KB
/
send_email.py
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
import smtplib
import arrow
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from beach_image import Image
from html_template import Email_Content
class SendEmail:
def send(send_list):
timezone = 'Europe/London'
Image.update()
# create email message
for recipent in send_list:
msg = MIMEMultipart()
msg['Subject'] = f'Bodley Weather Report {arrow.now(tz=timezone).format("DD-MM")}'
msg['From'] = '[email protected]'
msg['To'] = str(recipent)
msg.attach(MIMEText(Email_Content.write(), 'html'))
with open('/tmp/Beach_Image.png', 'rb') as f:
image = MIMEImage(f.read())
msg.attach(image)
image.add_header('Content-ID', '<Beach_Image.png>')
# send email
smtp_server = 'smtp.gmail.com'
smtp_port = 587
smtp_username = '[email protected]'
smtp_password = 'ExamplePassword'
smtp_conn = smtplib.SMTP(smtp_server, smtp_port)
smtp_conn.starttls()
smtp_conn.login(smtp_username, smtp_password)
smtp_conn.sendmail('[email protected]',
str(recipent), msg.as_string())
smtp_conn.quit()