-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmtp.py
37 lines (31 loc) · 941 Bytes
/
smtp.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
33
34
35
36
37
import smtplib
# Sample credentials (for demonstration purposes only)
smtp_s = "smtp.gmail.com"
smtp_p = 587
smtp_u = "[email protected]"
smtp_p = "rohit#@tiger"
# Create a connection to the SMTP server
server = smtplib.SMTP(smtp_server, smtp_port)
# Start TLS for security
server.starttls()
try:
# Log in to the server
server.login(smtp_user, smtp_p)
print("Logged in successfully")
# You can now send emails using server.sendmail() method
# Example:
# from_address = "[email protected]"
# to_address = "[email protected]"
# message = """\
# Subject: Test Email
#
# This is a test email.
# """
# server.sendmail(from_address, to_address, message)
except smtplib.SMTPAuthenticationError:
print("Failed to log in. Check your credentials.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Close the connection to the SMTP server
server.quit()