Advertisement
Sim0o0na

Mail Sender

Aug 31st, 2019
2,754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import smtplib
  2. from datetime import datetime
  3. from email.mime.multipart import MIMEMultipart
  4. from email.mime.text import MIMEText
  5.  
  6. # Fill in credentials here
  7. # Make sure you have enabled access to less secure apps in your google profile. You can do it from here
  8. # myaccount.google.com/lesssecureapps
  9. credentials = {'username': '',
  10. 'password': ''}
  11.  
  12. # Start connection
  13. server = smtplib.SMTP('smtp.gmail.com', 587)
  14. server.starttls()
  15.  
  16. # Log in to the server
  17. server.login(credentials['username'], credentials['password'])
  18.  
  19. # Build message
  20. message = MIMEMultipart()
  21. message['Subject'] = 'Demo Mail'
  22. message['From'] = ''
  23. message['To'] = ''
  24. message_text = f'Hello! This email is sent from demo! {datetime.now()}'
  25. body = MIMEText(message_text)
  26. message.attach(body)
  27.  
  28. # Send the mail
  29. server.send_message(message)
  30. print('Mail sent!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement