stoker

Email Sender with attachment

Jan 21st, 2014
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. # Connection...
  5.  
  6.  
  7. import smtplib
  8. import os
  9.  
  10. # Message Body....
  11.  
  12. from email import Encoders
  13. from email.MIMEBase import MIMEBase
  14. from email.MIMEMultipart import MIMEMultipart
  15. from email.MIMEText import MIMEText
  16.  
  17. print '''
  18.  
  19. # Python Email Sender.
  20. # Author: Muhammad Adeel aka Innoxent Stoker
  21. # FB: http://facebook.com/xtoker
  22.  
  23.  
  24.         _\|/_
  25.         (o o)
  26. +----oOO-{_}-OOo--------------+
  27. |==> author: Muhammad Adeel   +
  28. +==> FB.com/xtoker            +
  29. |==> [email protected]      +
  30. +-----------------------------+
  31. | Usage: "./MailSender.py"    |
  32. +-----------------------------+
  33. <<==============================>>
  34. +++++++++++++++++++++++++++++++
  35. |||||||||||||||||||||||||||||||
  36. +++++++++++++++++++++++++++++++
  37. |      InnoXent Stoker        |  
  38. +++++++++++++++++++++++++++++++
  39. |||||||||||||||||||||||||||||||
  40. +++++++++++++++++++++++++++++++
  41.  
  42.  
  43. '''
  44.  
  45. gmail_id = raw_input('Gmail Username/ID : ')
  46. gmail_pass =raw_input('Password: ')
  47. def mail(to, subject, text, attach):
  48.      
  49.     pesan = MIMEMultipart()
  50.  
  51.     pesan['From'] = gmail_id
  52.     pesan['To'] = to
  53.     pesan['Subject'] = sub
  54.  
  55.     pesan.attach(MIMEText(text))
  56.  
  57.     part = MIMEBase('application', 'octet-stream')
  58.     part.set_payload(open(attach, 'rb').read())
  59.     Encoders.encode_base64(part)
  60.     part.add_header('Content-Disposition',
  61.             'attachment; filename="%s"' % os.path.basename(attach))
  62.     pesan.attach(part)
  63.  
  64.     mailServer = smtplib.SMTP("smtp.gmail.com", 587)
  65.     mailServer.ehlo()
  66.     mailServer.starttls()    
  67.     mailServer.ehlo()
  68.     mailServer.login(gmail_id, gmail_pass)    
  69.     mailServer.sendmail(gmail_id, to, pesan.as_string())
  70.     mailServer.close()
  71.  
  72.  
  73.  
  74. more_send="y"
  75. recepients = []
  76.  
  77.  
  78. while more_send == "y":
  79.     get_recepient_email = raw_input("Recepient's Email: ")
  80.     recepients.append(get_recepient_email)
  81.     more_send = raw_input("Do you want to send more(y/n): ")
  82.  
  83.  
  84. sub = raw_input("Subject: ")
  85. body = raw_input("Body: ")
  86. file_path = raw_input("Enter attachment path: ")
  87.  
  88. for email in recepients:
  89.     mail(email,sub,body,file_path)
  90.     print "Your email to "+str(email)+" was sent successfully"
Add Comment
Please, Sign In to add comment