Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # USAGE: ./sendgmail.py path_to_filename [assigned_attachment_name]
  4. # if not assign assigned_attachment_name, the attachment is named as original path_to_filename
  5.  
  6. from email.mime.text import MIMEText
  7. from email.mime.application import MIMEApplication
  8. from email.mime.multipart import MIMEMultipart
  9. from smtplib import SMTP
  10. import smtplib
  11. import sys
  12.  
  13. sender = '{YOUR_ID}@gmail.com'
  14. passwd = '{YOUR_PASSWD}'
  15. receivers = ['{RECEIVER_1}@gmail.com','{RECEIVER_2}@gmail.com']
  16.  
  17. emails = [elem.strip().split(',') for elem in receivers]
  18. msg = MIMEMultipart()
  19. msg['Subject'] = "{YOUR_MAIL_SUBJECT}"
  20. msg['From'] = sender
  21. msg['To'] = ','.join(receivers)
  22.  
  23. msg.preamble = 'Multipart massage.\n'
  24. part = MIMEText("{YOUR_MAIL_CONTENT}")
  25. msg.attach(part)
  26.  
  27. part = MIMEApplication(open(str(sys.argv[1]),"rb").read())
  28. if not sys.argv[2]:
  29. attachname = str(sys.argv[1])
  30. else:
  31. attachname = str(sys.argv[2])
  32.  
  33. part.add_header('Content-Disposition', 'attachment', filename=attachname)
  34. msg.attach(part)
  35.  
  36. smtp = smtplib.SMTP("smtp.gmail.com:587")
  37. smtp.ehlo()
  38. smtp.starttls()
  39. smtp.login(sender, passwd)
  40.  
  41. smtp.sendmail(msg['From'], emails , msg.as_string())
  42. print 'Send mails to',msg['To']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement