SEND AN EMAIL USING SMTP IN PYTHON

import smtplib

def send_email():
    sender = "your_email@gmail.com"
    password = "your_password"
    recipient = "recipient_email@gmail.com"
    subject = "Test Email"
    body = "This is a test email sent using Python."

    message = f"Subject: {subject}\n\n{body}"
    
    with smtplib.SMTP("smtp.gmail.com", 587) as server:
        server.starttls()
        server.login(sender, password)
        server.sendmail(sender, recipient, message)
        print("Email sent successfully!")

# Call the function
# send_email()
Python

Leave a Reply

Your email address will not be published. Required fields are marked *


error: Content is protected !!
Scroll to Top
MacroNepal
Verified by MonsterInsights