-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
51 lines (42 loc) · 1.33 KB
/
test.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
41
42
43
44
45
46
47
48
49
50
51
import smtplib
from asdf import outputText
# sender='[email protected]'
# receiver='[email protected]'
# password=""
# smtpserver=smtplib.SMTP("smtp.gmail.com",587)
# smtpserver.ehlo()
# smtpserver.starttls()
# smtpserver.ehlo
# smtpserver.login(sender,password)
# msg=outputText
# smtpserver.sendmail(sender,receiver,msg)
# print('Sent')
# smtpserver.close()
# Import smtplib to provide email functions
# Import the email modules
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# Define email addresses to use
addr_to = '[email protected]'
addr_from = "[email protected]"
# Define SMTP email server details
smtp_server = 'smtp.gmail.com'
smtp_user = '[email protected]'
smtp_pass = 'xxxxxx'
# Construct email
msg = MIMEMultipart('alternative')
msg['To'] = addr_to
msg['From'] = addr_from
msg['Subject'] = 'Test Email '
# Record the MIME types of both parts - text/plain and text/html.
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(MIMEText(outputText, 'html'))
# Send the message via an SMTP server
s = smtplib.SMTP(smtp_server, 587)
s.ehlo()
s.starttls()
s.login(smtp_user, smtp_pass)
s.sendmail(addr_from, addr_to, msg.as_string())
s.quit()