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

What is __init__?

0 Answers  


How is it possible to share global variables across various modules?

0 Answers  


What is python basic syntax?

0 Answers  


What is micropython?

0 Answers  


What are the features of python?

0 Answers  






What is __ init__ in python?

0 Answers  


What are the differences between c and python?

0 Answers  


What is a function?

0 Answers  


How do you use return in python?

0 Answers  


What does slicing mean in python?

0 Answers  


What is super in python class?

0 Answers  


Is python written in python?

0 Answers  


Categories