-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemailusinggmail.py
More file actions
52 lines (37 loc) · 927 Bytes
/
Copy pathemailusinggmail.py
File metadata and controls
52 lines (37 loc) · 927 Bytes
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
52
# Import SMTP Library
import smtplib
import ssl
# Import email modules
from email.message import EmailMessage
# SMTP Server
server = 'tls://smtp.gmail.com'
port = 587
user = 'yourname@gmail.com'
password = 'password'
# Sender and Receiver
sender = 'yourname@gmail.com'
receivers = ['receiver@gmail.com']
# Message
message = EmailMessage()
message['From'] = sender
message['To'] = receivers
message['MIME-Version'] = '1.0'
message['Content-type']: 'text/html'
message['Subject'] = 'Welcome'
message.set_content('Welcome Guest !!')
# Create SSL context
context = ssl.create_default_context()
# Send email
try:
smtpObj = smtplib.SMTP(server, port)
smtpObj.ehlo()
smtpObj.starttls(context=context)
smtpObj.ehlo()
smtpObj.login(user, password)
smtpObj.send_message(message)
print("Email sent")
except smtplib.SMTPException as exc:
print("Error sending email")
print(exc)
finally:
smtpObj.quit()