Advertisement
osx11

[Python] Emailer

Apr 12th, 2019
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import smtplib
  2. from sys import argv
  3. from email.mime.text import MIMEText
  4. from email.header import Header
  5.  
  6. MAIL_SMTP = "smtp.email.com:465"
  7. MAIL_ACCOUNT = "account@email.com"
  8. MAIL_PASSWORD = "password"
  9.  
  10. if __name__ == "__main__":
  11.     if len(argv) != 4:  # 4, т.к. 0  по умолчанию == "__main__"
  12.         print("Usage: emailer.py [target] [header] [text]")
  13.         exit(0)
  14.  
  15.     TARGET = argv[1]
  16.     HEADER = argv[2]
  17.     MESSAGE = argv[3]
  18.  
  19.     mail_message = MIMEText(MESSAGE, 'plain', 'utf-8')
  20.     mail_message['Subject'] = Header(HEADER, 'utf-8')
  21.  
  22.     server = smtplib.SMTP_SSL(MAIL_SMTP)
  23.     server.set_debuglevel(0)
  24.     server.login(MAIL_ACCOUNT, MAIL_PASSWORD)
  25.     server.sendmail(MAIL_ACCOUNT, TARGET, mail_message.as_string())
  26.     server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement