-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsending email using python.py
More file actions
35 lines (33 loc) · 1.21 KB
/
sending email using python.py
File metadata and controls
35 lines (33 loc) · 1.21 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
import smtplib, ssl
sender_email = "madval1369@gmail.com"
password = "rwdfntxebjstxfig"
receiver_email = "mohammad.pfallah@gmail.com"
message = "Subject: Hi there\nThis message is sent from Python."
smtp_server = "smtp.gmail.com"
port = 465 # For SSL
# port = 587 # For starttls
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
print('Email Sent!!!')
# import smtplib, ssl
# sender_email = "madval1369@gmail.com"
# password = "rwdfntxebjstxfig"
# receiver_email = "mohammad.pfallah@gmail.com"
# message = "Subject: Hi there\nThis message is sent from Python."
# smtp_server = "smtp.gmail.com"
# port = 587 # For starttls
# context = ssl.create_default_context()
# try:
# with smtplib.SMTP(smtp_server, port) as server:
# server.ehlo() # Can be omitted
# server.starttls(context=context)
# server.ehlo() # Can be omitted
# server.login(sender_email, password)
# server.sendmail(sender_email, receiver_email, message)
# print('Email Sent!!!')
# except Exception as e:
# print(e)
# finally:
# server.quit()