Send Emails With Python , SMTP

    Hey fellas! If you know basics of Python and want to learn more, then this article is for you. In this article we will discuss on use of SMTP for sending emails with Python. SMTP stands for Simple Mail Transfer Protocol and you can read its definition from here. Here, we are going to show you how to simply send emails with Python code.

    To send emails with Python, we use a module called smtplib. Basically, what you have to do is write a piece of code including the sending and receiving emails, the password for your email and the message. The necessary things to be considered to send emails with Python are listed below:

    1. host : The host for this purpose is “”
    2. port : The port we are going to use is 587.
    3. sender :It is the email address of sender.
    4. receiver : It is basically the email of receiver.

    The code: Send emails with Python:

    username = “”
    password = “enter your password here”
    host = “”
    port = 587
    sender = username
    receiver = “name of receiver”
    message =”Yo man you are a genius. ”
    emailfn = smtplib.SMTP(host, port)
    emailfn.starttls() #This is for security layer.
    emailfn.login(username, password) #This line is for login.
    emailfn.sendmail(sender, receiver, message) #This function is for sending the mail.
    emailfn.quit() #It is very important to quit and logout after our work is done.

    Also read: Create a module in Python.


    All you have to do is enter your email in the username and the receiving email in receiver part. I have tried to make everything clear in the comment of the code. Fairly simple right? The best thing about Python is it’s code is so simple to read that you can guess what is going on just by looking at the code. It is also fun to learn Python as it is easy to understand.

    If you have any queries on the article you can ask in the comment section. Also, if you have any suggestions or complaints on our contents we will be happy to see them in the comment section. If you want more articles on Python feel free to comment so that we can give you articles that will be useful. Also leave a like on our Facebook page.





    Recent Articles

    How to Get Free Virtual Credit Card | Physical VCC | 2020 | Payoneer

    Previously we have posted an article about virtual credit card about Yandex Method. Which is not working great like it used to. So here's...

    How To Install SIB Panel | Dump Combos | 2020

    In our previous article, We discussed about Making HQ dorks today we will discuss on how to install sib panel. If you are into...

    How to use TOR as VPN | TOR VPN | 2020 | Protect your identity online

    Yes, you heard it right, use Tor as a VPN, i.e. TOR VPN. It may sound weird, but you can use TOR as a...

    Get 5k$ Amazon Credit For Free | 2020 | 100% Working Method

    Amazon Credit For Free - If you are running web and application servers in the cloud or deliver static and dynamic files quickly around...

    How to remove region code to backup DVD easily | 2020

    I love travel around the world and my friends the same as me. Of course, our every travelling finished with some special souvenir took...

    Related Stories

    Stay on op - Ge the daily news in your inbox