-
Notifications
You must be signed in to change notification settings - Fork 13
/
Email_Sender_App.py
32 lines (26 loc) · 1.1 KB
/
Email_Sender_App.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
'''
GoTo sender's Gmail account first and turn_On/Allow the toggle of "Access of Less Secure Apps" using this link-
https://www.google.com/settings/security/lesssecureapps so that SMTP server can login to sender's gmail account without
security errors.
'''
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = 'simple email in python 3'
message = 'here is the email hello sir'
msg.attach(MIMEText(message))
def SendEmail(From, to, content):
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo() # identify ourselves to smtp gmail client
server.starttls() # secure our email with tls encryption
server.login(From, 'Your_email_password') # Update your Email password here!
server.sendmail(From, to, content)
print("Mail Sent Successfully!")
except:
print("Error occurred while sending mail")
SendEmail(msg['From'], msg['To'], msg.as_string())
### End of Code ###