Skip to content

Instantly share code, notes, and snippets.

@joneskoo
Created October 25, 2011 05:43
Show Gist options
  • Save joneskoo/1311419 to your computer and use it in GitHub Desktop.
Save joneskoo/1311419 to your computer and use it in GitHub Desktop.
Python spammer with unicode support
#!/usr/bin/env python3
# encoding: utf-8
import smtplib
from email.message import Message
from email.header import Header
from email.utils import formataddr
SMTP_SERVER = 'mail.suomi.net'
FROM_NAME = 'Example Sender'
FROM_EMAIL = 'from@example.com'
TOADDRS = [('Example Receiver', 'to@example.com')]
TEXT = "Tässäpä on pitkä tekstiviesti.\nÄäkköset ja €-merkit eivät ole ongelma."
SUBJECT = "Tämä on taas kerran testiviesti"
def main():
from_header = "{} <{}>".format(Header(FROM_NAME), FROM_EMAIL)
subject = Header(SUBJECT, 'utf-8')
server = smtplib.SMTP(SMTP_SERVER)
server.set_debuglevel(1)
for to_name, to_email in TOADDRS:
msg = Message()
msg['Subject'] = subject
msg['From'] = from_header
msg['To'] = "{} <{}>".format(Header(to_name), to_email)
msg.set_payload(TEXT, 'utf-8')
server.sendmail(FROM_EMAIL, to_email, msg.as_string())
server.quit()
if __name__ == '__main__':
main()
@joneskoo
Copy link
Author

Does not validate to_email, which may be bad if the email source is untrusted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment