Describe how to send mail from a Python script.



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

Post New Answer

More Python Interview Questions

“In Python, functions are first-class objects.” What do you infer from this?

2 Answers  


Explain the use of the split function in python?

0 Answers  


What does the continue do in python?

0 Answers  


What is arange function in python?

0 Answers  


What is the purpose of the pythonpath environment variable?

0 Answers  


When would you use a break statement in a for loop?

0 Answers  


What causes static?

0 Answers  


What is dynamic typing in python?

0 Answers  


What is the dictionary in Python?

0 Answers  


What is the starting point of python code execution?

0 Answers  


What does __name__=='__main__' in python mean?

0 Answers  


What are accessors, mutators, and @property?

0 Answers  


Categories