Guest User

Untitled

a guest
May 7th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. __author__ = 'srv'
  2.  
  3. import smtplib
  4. from email.mime.multipart import MIMEMultipart
  5. from email.mime.text import MIMEText
  6. from email.mime.application import MIMEApplication
  7.  
  8. username = '' # Email Address from the email you want to send an email
  9. password = '' # Password
  10. server = smtplib.SMTP('')
  11.  
  12. """
  13. SMTP Server Information
  14. 1. Gmail.com: smtp.gmail.com:587
  15. 2. Outlook.com: smtp-mail.outlook.com:587
  16. 3. Office 365: outlook.office365.com
  17. Please verify your SMTP settings info.
  18. """
  19.  
  20. # Create the body of the message (a HTML version for formatting).
  21. html = """Add you email body here"""
  22.  
  23.  
  24. # Function that send email.
  25. def send_mail(username, password, from_addr, to_addrs, msg):
  26. server = smtplib.SMTP('smtp-mail.outlook.com', '587')
  27. server.ehlo()
  28. server.starttls()
  29. server.ehlo()
  30. server.login(username, password)
  31. server.sendmail(from_addr, to_addrs, msg.as_string())
  32. server.quit()
  33.  
  34. # Read email list txt
  35. email_list = [line.strip() for line in open('email.txt')]
  36.  
  37. for to_addrs in email_list:
  38. msg = MIMEMultipart()
  39.  
  40. msg['Subject'] = "Hello How are you ?"
  41. msg['From'] = from_addr
  42. msg['To'] = to_addrs
  43.  
  44. # Attach HTML to the email
  45. body = MIMEText(html, 'html')
  46. msg.attach(body)
  47.  
  48. # Attach Cover Letter to the email
  49. cover_letter = MIMEApplication(open("file1.pdf", "rb").read())
  50. cover_letter.add_header('Content-Disposition', 'attachment', filename="file1.pdf")
  51. msg.attach(cover_letter)
  52.  
  53. # Attach Resume to the email
  54. cover_letter = MIMEApplication(open("file2.pdf", "rb").read())
  55. cover_letter.add_header('Content-Disposition', 'attachment', filename="file2.pdf")
  56. msg.attach(cover_letter)
  57.  
  58. try:
  59. send_mail(username, password, from_addr, to_addrs, msg)
  60. print "Email successfully sent to", to_addrs
  61. except SMTPAuthenticationError:
  62. print 'SMTPAuthenticationError'
  63. print "Email not sent to", to_addrs
Add Comment
Please, Sign In to add comment