-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_smtp.py
28 lines (23 loc) · 997 Bytes
/
send_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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Send mail for schedule
# Values that will not be changed
smtp_server = '10.11.11.50' # Replace with your SMTP server address
smtp_port = 25 # Replace with the appropriate SMTP port (587 is commonly used for TLS)
sender_email = 'agenda@personal.com.py' # Replace with your email address
def sendEmail(body, receiver_email, subject):
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = ','.join(receiver_email)
msg['Subject'] = subject
# Add the UTF-8 encoded body to the email
msg.attach(MIMEText(body, 'html', 'utf-8'))
try:
# Establish a connection to the SMTP server
with smtplib.SMTP(smtp_server, smtp_port) as server:
# Send the email
server.sendmail(sender_email, receiver_email, msg.as_string())
print("Email sent successfully!")
except Exception as e:
print(f"An error occurred: {e}")