Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Describe how to send mail from a Python script.

Answer Posted / chaitanya

The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine.

A sample email is demonstrated below.

import smtplib

SERVER = smtplib.SMTP(‘smtp.server.domain’)

FROM = sender@mail.com

TO = ["user@mail.com"] # must be a list

SUBJECT = "Hello!"

TEXT = "This message was sent with Python's smtplib."

# Main message

message = """

From: Sarah Naaz < sender@mail.com >

To: CarreerRide user@mail.com

Subject: SMTP email msg

This is a test email. Acknowledge the email by responding.

""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

server = smtplib.SMTP(SERVER)

server.sendmail(FROM, TO, message)

server.quit()

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by instantiating a class?

857


Do I need to learn c++ before python?

861


What are python libraries?

858


What is an interpreter for python?

823


Why should we close files?

933


How to walk through a list in a sorted order without sorting the actual list?

1095


how do I protect python code?

838


Explain what is the common way for the flask script to work?

824


Rules for local and global variables in python?

958


How will you reload a module of python, explain?

795


What does super () mean in python?

795


What is unboundlocalerror in python?

851


What is the use of negative indices?

872


What is python package manager (pypm)?

905


What are the differences between the threading and multiprocessing in python?

890