-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_sender.py
32 lines (25 loc) · 1.14 KB
/
email_sender.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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(sender_email, sender_password, recipients, subject, message):
try:
smtp_server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtp_server.login(sender_email, sender_password)
for recipient in recipients:
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
smtp_server.sendmail(sender_email, recipient, msg.as_string())
smtp_server.quit()
print("Email(s) sent successfully!")
except Exception as e:
print("Failed to send email:", e)
if __name__ == "__main__":
sender_email = "[email protected]"
sender_password = "your_password"
recipients = ["[email protected]", "[email protected]"]
subject = "Test Email"
message = "This is a test email sent using Python. This script is using for loop to send the same email to everyone"
send_email(sender_email, sender_password, recipients, subject, message)