-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmail.py
29 lines (20 loc) · 854 Bytes
/
sendmail.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
# Sending email using SSL Connection
import smtplib, ssl
import getpass
port = 465 # for SSL
smtp_server = "smtp.gmail.com"
sender_email = "[email protected]" # your email
reciever_email = "[email protected]" # recievers email
# for sending to multiple emails create a list like below
# reciever_email = ["[email protected]","[email protected]"]
message = """\
Subject: Hi there
This message is sent from Python."""
password = getpass.getpass(prompt='Password: ', stream=None)
# getpass() used to hide typing password in prompt
# creating a secure SSL context
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login("[email protected]", password)
server.sendmail(sender_email, reciever_email, message)
# Server is automatically closed after getting out from with block