-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextEmailSentUsingPython.py
More file actions
38 lines (29 loc) · 957 Bytes
/
TextEmailSentUsingPython.py
File metadata and controls
38 lines (29 loc) · 957 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
import smtplib as s
# Define the SMTP server
SMTP_SERVER = 'smtp.gmail.com'
PORT = 587
# Define email credentials
email_address = ''
password = ''
# Define email content
subject = ""
body = """
"""
message = "Subject: {}\n\n{}".format(subject, body)
# Define recipient email addresses
recipients = ['']
try:
# Connect to the SMTP server
with s.SMTP(SMTP_SERVER, PORT) as smtp:
smtp.ehlo() # Identify ourselves to the SMTP server
smtp.starttls() # Start TLS encryption
smtp.ehlo() # Re-identify ourselves as an encrypted connection
# Log in to the email account
smtp.login(email_address, password)
# Send the email
smtp.sendmail(email_address, recipients, message)
print("Mail Send Successfully.")
except Exception as e:
# Print an error message if the email fails to send
print("Failed to send mail.")
print(f"Error: {e}")