DEV Community

Omale Happiness Ojone
Omale Happiness Ojone

Posted on

2 1

How to send emails using python

What are emails?
Emails are messages distributed by electronic means from one computer user to another. There can be many more recipient as well via network.

Methods we can use to send an email:

  1. We can use python web automation using selenium.
  2. We have a python library which is SMTP library which can be used to send an email.
    But for this article I shall be explaining how to use the STMP library.
    STMP which means simple transfer mail protocol. STMP library, this library or the modules defines an SMTP clients session object which can be used to send an email to any other internet machine with an STMP or E-STMP listener daemon.

    Here's the full code

          :
          import smtplib
          server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
          server.login('example@gmail.com', 'password')
          server.sendmail('example@gmail.com', 
          'contact1@gmail.com', 'Hi happiness,how are you?')
          server.quit()
    

Quickly what you should note:
"example@gmail.com"-your email address should be there
"password"-the password to your email address
"contact1@gmail.com"-the receiver's email address.
then you go ahead with the body of the message.

So here's the output
gmail ans.JPG

Finally you have to enable your "less secure app" from your google account in order to send the message.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay