-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsending_email.py
40 lines (29 loc) · 1017 Bytes
/
sending_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
40
#################
# Module with function for sending emails.
#################
import smtplib # send the email
from email.mime.multipart import MIMEMultipart # email body
from email.mime.text import MIMEText # email body
import smtp # personal smtp settings
def sendemail(sbj='No-subject',cnt='Email body not specified.'):
print('Composing Email...')
# update your email details
SERVER = smtp.SERVER # smtp server
PORT = smtp.PORT # port number
FROM = smtp.FROM # sender's email
TO = smtp.TO # receiver's email (can be a list)
PASS = smtp.PASS # sender's email smtp password
msg = MIMEMultipart()
msg['Subject'] = sbj
msg['From'] = FROM
msg['To'] = TO
msg.attach(MIMEText(cnt, 'html'))
print('Initiating Server...')
server = smtplib.SMTP_SSL(SERVER, PORT)
server.set_debuglevel(1)
server.ehlo()
#server.starttls()
server.login(FROM, PASS)
server.sendmail(FROM, TO, msg.as_string())
print('Email Sent...')
server.quit()