Describe how to send mail from a Python script.
Answer / 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 |
How do you execute a python script?
What is a function call or a callable object in python?
Does return print in python?
Do they know a tuple/list/dict when they see it?
What is the use of __ init __ py in python?
python is case sensitive ?
What is the purpose of #!/usr/bin/pythonon the first line in the above code? Is there any advantage?
Does python perform tail recursion optimization?
What happens if we do not handle an error in the except block?
Write a program to reverse the string?
Is python call by reference or value?
Point out some of the key features of python?