import smtplib server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.login("sender_email_address", "sender_email_password") message = "Hello, world!" server.sendmail("sender_email_address", "receiver_email_address", message) server.quit()
from email.mime.text import MIMEText import smtplib message = MIMEText("Hello, world!") message['From'] = "sender_email_address" message['To'] = "receiver_email_address" message['Subject'] = "Greeting from Python" server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.login("sender_email_address", "sender_email_password") server.sendmail("sender_email_address", "receiver_email_address", message.as_string()) server.quit()In this code example, we use MIMEText to create an email message with content and set up the email headers with sender and recipient addresses as well as a subject line. The code then establishes an SSL/TLS secure connection to the Gmail SMTP server and sends the email message using the SMTP_SSL object. The package library used is the standard smtplib library, which is included in the Python standard library.