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 |
What is the purpose of bytes() in python?
Explain the use of try: except raise, and finally?
Explain the uses of the modules sqlite3, ctypes, pickle, traceback, and itertools.
What is uuid format?
How does Python handle the memory management?
Do you always need a default constructor?
What do you understand by *args and **kwarg python?
Explain about assert statement?
What are python namespaces?
How to improve performance of this code?
Does python have long?
What is flask?