Skip to content

Instantly share code, notes, and snippets.

@LordGhostX
Last active January 30, 2022 21:03
Show Gist options
  • Save LordGhostX/6ed1b58a952f85944def435f13578c35 to your computer and use it in GitHub Desktop.
Save LordGhostX/6ed1b58a952f85944def435f13578c35 to your computer and use it in GitHub Desktop.
Tiny Email Script
import time
import random
import smtplib
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
host = ""
port = 465
sender = ""
password = ""
subject = "Subject"
message = "Message"
def send_emails(emails, email_type="plain"):
context = ssl.create_default_context()
with smtplib.SMTP_SSL(host, port, context=context) as server:
server.ehlo()
server.login(sender, password)
for email in emails:
user = [i.strip() for i in email.split(",")]
try:
msg = MIMEMultipart("alternative")
msg["Subject"] = subject
msg["From"] = sender
msg["To"] = user[0]
msg.attach(MIMEText(message, email_type))
server.sendmail(sender, user[0], msg.as_string())
print("Finished sending email to", user[0])
except:
print("An error occured while sending email to", user[0])
time.sleep(random.randint(1, 3))
send_emails(open("people.csv", "r").read().strip().split("\n")[1:], "plain")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment