Skip to main content

Python code to send mail from gmail

 import smtplib

from email.mime.text import MIMEText

# Email and app password setup

sender_email = "sender@gmail.com"

receiver_email = "receiver@gmail.com"

password = "gmailapppassword"  # Use Gmail App Password, not your normal password

# Email content

subject = "Test Email from Python"

body = "This is a test email sent from a Python script."


# Create MIMEText object

msg = MIMEText(body)

msg['Subject'] = subject

msg['From'] = sender_email

msg['To'] = receiver_email


# Connect to Gmail SMTP server and send email

try:

    with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp_server:

        smtp_server.login(sender_email, password)

        smtp_server.sendmail(sender_email, receiver_email, msg.as_string())

    print("Email sent successfully!")

except Exception as e:

    print(f"Failed to send email: {e}")

Comments

Popular posts from this blog

Convex Lens Vs Concave Lens

What is a Lens A lens is a transparent object that transmits light across it, and its working principle depends on the   law of refraction (Snell’s law) . Applications: Concave Lens help with Far-Sight Convex Lens help with Near-Sight

Herbal Plants

Herbal plants to grow in home Different types of keerai ----- http://www.indiandietrecipes.com/2016/03/pictures-of-various-types-of-greens-or.html Pirandai ----good for bone joins---- https://youtu.be/k2DGubyXLAE Valarai Keerai Benifits ----- https://youtu.be/33HIfLJKTqA Sesma seeds ---- https://easyayurveda.com/2011/02/24/sesame-and-sesame-oil-benefits-total-ayurveda-details/

What is Verbal and Non-Verbal communication

TYPES OF COMMUNICATIONS: