-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (26 loc) · 970 Bytes
/
main.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
# This is a code for testing emails sent. Mailtrap works as ga virtual inbox.
import smtplib
from socket import gaierror
port = 2525 # use one of the three options in Mailtrap
smtp_server = "smtp.mailtrap.io"
login = "x" # your login generated by Mailtrap
password = "y" # your password generated by Mailtrap
sender = "x"
receiver = "y"
message = f"""\
Subject: Greetings,
To: {receiver}
From: {sender}
..."""
try:
with smtplib.SMTP(smtp_server, port) as server:
server.login(login, password)
server.sendmail(sender, receiver, message)
# tell the script to report if your message was sent or which errors need to be fixed
print('Sent')
except (gaierror, ConnectionRefusedError):
print('Failed to connect to the server. Bad connection settings?')
except smtplib.SMTPServerDisconnected:
print('Failed to connect to the server. Wrong user/password?')
except smtplib.SMTPException as e:
print('SMTP error occurred: ' + str(e))