How to send an email in Python Language?

Last updated 3 weeks, 5 days ago | 22 views 75     5

Tags:- Python

Python | Send an email

To send an email, Python provides smtplib and email modules. Import these modules into the created mail script and send mail by authenticating a user. It has a method SMTP(smtp-server, port). It requires two parameters to establish SMTP connection.
 

import smtplib  
  
# Calling SMTP    
s = smtplib.SMTP('smtp.gmail.com', 587)  
  
# TLS for network security    
s.starttls()
    
# User email Authentication    
s.login("sender@email_id", "sender_email_id_password")
    
# Message to be sent    
message = "Message_sender_need_to_send" 
   
# Sending the mail    
s.sendmail("sender@email_id ", "receiver@email_id", message)