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

Is python 0 based?

0 Answers  


Is upper in python?

0 Answers  


Is sorted in python?

0 Answers  


Why are identifier names with a leading underscore disparaged?

0 Answers  


Where we can use else block in python programming?

0 Answers  


Is python a scripting or programming?

0 Answers  


Does python supports hybrid inheritance?

0 Answers  


How do you sort a list alphabetically in python with sort function?

0 Answers  


What is monkey Patching in python?

0 Answers  


How do you split a string in python?

0 Answers  


How do you count loops in python?

0 Answers  


What do you mean by the dictionary in python?

0 Answers  


Categories