Here’s how you can quickly send an email with Gmail using the Yagmail library:
- Install Yagmail by running the command
pip install yagmailin your shell.
- Install Keyring by running the command
pip install keyringin your shell.
- Execute the following code snippet (specify your own username, password, and email content):
import yagmail yag = yagmail.SMTP('username', 'password') yag.send(to = 'email@example.com', subject = 'hi', contents = 'Just wanted to say "hi"')
Voilà. You can consult the README to find out about more features such as sending HTML messages.
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.