Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. ImportError: No module named mime.multipart
  2.  
  3. # coding=utf-8
  4. # Copyright (C) 2014 Stefano Guglielmetti
  5.  
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14.  
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. import smtplib, os, sys
  19. from email.MIMEMultipart import MIMEMultipart
  20. from email.MIMEBase import MIMEBase
  21. from email.MIMEText import MIMEText
  22. from email.Utils import COMMASPACE, formatdate
  23. from email import Encoders
  24.  
  25. #From address, to address, subject and message body
  26. from_address = 'FROM_ADDRESS@EMAIL.COM'
  27. to_address = ['YOUR_ADDRESS@EMAIL.COM']
  28. email_subject = 'Alert!!! Zombies!!! Ahead!!!'
  29. email_body = 'A non dead intruder has been detected and needs to be eliminated!'
  30.  
  31. # Credentials (if needed)
  32. username = 'EMAIL_LOGIN'
  33. password = 'EMAIL_PASSWORD'
  34.  
  35. # The actual mail send
  36. server = 'smtp.gmail.com:587'
  37.  
  38. def send_mail(send_from, send_to, subject, text, files=[], server="localhost"):
  39. assert type(send_to)==list
  40. assert type(files)==list
  41.  
  42. msg = MIMEMultipart()
  43. msg['From'] = send_from
  44. msg['To'] = COMMASPACE.join(send_to)
  45. msg['Date'] = formatdate(localtime=True)
  46. msg['Subject'] = subject
  47.  
  48. msg.attach( MIMEText(text) )
  49.  
  50. for f in files:
  51. part = MIMEBase('application', "octet-stream")
  52. part.set_payload( open(f,"rb").read() )
  53. Encoders.encode_base64(part)
  54. part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
  55. msg.attach(part)
  56.  
  57. smtp = smtplib.SMTP(server)
  58. smtp.starttls()
  59. smtp.login(username,password)
  60. smtp.sendmail(send_from, send_to, msg.as_string())
  61. smtp.close()
  62.  
  63. send_mail(from_address, to_address, email_subject, email_body, [sys.argv[1]], server) #the first command line argument will be used as the image file name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement