Python Send Emails

python day 30

Can you believe we can use Python to send emails?📩

To my surprise, it actually works! 😜

So today Iet’s try to send an email from gmail using python with
“Yibo asks you to play the skateboard” 🙈🙈🙈🙈🙈

  • Module: email, smtplib 

✨ Trick: Turn ON Gmail less secure pass

Python Code:

import email
import smtplib

msg = email.message_from_string('Yibo asks you to play the skateboard')
msg['From'] = "myemail@gmail.com"
msg['To'] = "myemail@gmail.com"
msg['Subject'] = "Hola hola"

s = smtplib.SMTP("smtp.gmail.com",587)
s.ehlo() # Hostname to send for this command defaults to the fully qualified domain name of the local host.
s.starttls() #Puts connection to SMTP server in TLS mode
s.ehlo()
s.login('myemail@gmail.com', 'iloveu')

s.sendmail("myemail@gmail.com", "myemail@gmail.com",  msg.as_string())

s.quit()

You’ve got a mail:

王一博喊你去玩滑板了!!!

Happy Studying! I’m going to go skateboarding now !!!

Note: I didn’t try Hotmail or other mails, please let me know if it works.

Reference:

https://stackoverflow.com/questions/13411486/send-email-via-hotmail-in-python

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: