Advertisement
steve-shambles-2109

Send email with attachments using gmail

Dec 2nd, 2019
3,943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. '''Send email with attachments using gmail.
  2.   By Steve Shambles.
  3.   stevepython.wordpress.com
  4.  
  5.   pip3 install yagmail
  6. '''
  7. import yagmail
  8.  
  9. # set up your gmail credentials.
  10. # any problems could be gmail blocking you or wrong pw etc.
  11. # I had to allow unsafe apps in my gmail security
  12. # settings to get this to work.
  13.  
  14. YAG_SMTP = yagmail.SMTP(user="your@gmail.com",
  15.                         password="your-password",
  16.                         host='smtp.gmail.com')
  17.  
  18. # email subject
  19. SUBJECT = 'Yagmail Test'
  20.  
  21. # email content with attached file from current dir.
  22. CONTENTS = ['Hi Dude', 'image attached innit.', 'some-image.jpg']
  23.  
  24. # send mail
  25. YAG_SMTP.send('person@anymail.com', SUBJECT, CONTENTS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement