# [SOLVED] Help me to send an email using python



## ajainakp (Mar 25, 2011)

Hai,


Can anyone help me to identify the error what I made 
in this code to send the mail properly? 
Should I do any system configration/settings for this?

Thanks in advance

program I have written: (please look at the image attachment to get more idea)
-------------------

import smtplib
sender = '[email protected]'
receivers = ['[email protected]******.com']
message = """From: From Person <[email protected]>
To: To Person <[email protected]******.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message) 
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"


----------



## Ninjaboi (Dec 27, 2010)

*Re: Help me to send an email using python*

Hello ajainakp.

Here is a simple example to look at if you'd like:

How to Send Email with Python « The Mouse Vs. The Python

You might also be interested in looking at this one here:

18.1.11. email: Examples — Python v2.7.1 documentation


----------



## ajainakp (Mar 25, 2011)

*Re: Help me to send an email using python*

Hai Ninja,

Thanks for the helping me again, the article and Email code are very simple and useful but I tried with the code snippet but the following 
error is coming, your help and advice is needed. Please note the
image attachment too.


----------



## Ninjaboi (Dec 27, 2010)

*Re: Help me to send an email using python*

For your "connection refused" error, check this link out.


----------



## ajainakp (Mar 25, 2011)

*Re: Help me to send an email using python*

Hi Ninja,

Thank you so much for the help.


----------

