473,765 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sending emails using python

iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error
fromAddress = 's************* *@satyam.com'
toAddress = 's************* *@satyam.com'
msg = "Subject: Hello\n\nThis is the body of the message."
import smtplib
server = smtplib.SMTP("h stmsg002",25)
server.sendmail (fromAddress, toAddress, msg)

error:

Traceback (most recent call last):
File
"C:\sridhar\Beg inning_Python\B eginning_Python \Chapter16\tryi tout\InitialMai lExample.py",
line 5, in ?
server = smtplib.SMTP("h stmsg002",25)
File "C:\Python24\li b\smtplib.py", line 244, in __init__
(code, msg) = self.connect(ho st, port)
File "C:\Python24\li b\smtplib.py", line 307, in connect
(code, msg) = self.getreply()
File "C:\Python24\li b\smtplib.py", line 351, in getreply
raise SMTPServerDisco nnected("Connec tion unexpectedly closed")
SMTPServerDisco nnected: Connection unexpectedly closed

Sep 7 '06 #1
14 9900
sridhar enlightened us with:
iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error
fromAddress = 's************* *@satyam.com'
toAddress = 's************* *@satyam.com'
msg = "Subject: Hello\n\nThis is the body of the message."
^^^^

You need \r\n\r\n there. Line-ends in email messages should be DOS
line-ends.
Traceback (most recent call last):
File
"C:\sridhar\Beg inning_Python\B eginning_Python \Chapter16\tryi tout\InitialMai lExample.py",
line 5, in ?
server = smtplib.SMTP("h stmsg002",25)
File "C:\Python24\li b\smtplib.py", line 244, in __init__
(code, msg) = self.connect(ho st, port)
File "C:\Python24\li b\smtplib.py", line 307, in connect
(code, msg) = self.getreply()
File "C:\Python24\li b\smtplib.py", line 351, in getreply
raise SMTPServerDisco nnected("Connec tion unexpectedly closed")
SMTPServerDisco nnected: Connection unexpectedly closed
Well that's useless. You could install a network sniffer
(http://www.ethereal.com/) and find out what's actually sent over the
network connection, and where things go wrong.

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Sep 7 '06 #2
On 07/09/06, Sybren Stuvel <sy*******@your thirdtower.com. imaginationwrot e:
sridhar enlightened us with:
iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error

Traceback (most recent call last):
File
"C:\sridhar\Beg inning_Python\B eginning_Python \Chapter16\tryi tout\InitialMai lExample.py",
line 5, in ?
server = smtplib.SMTP("h stmsg002",25)
File "C:\Python24\li b\smtplib.py", line 244, in __init__
(code, msg) = self.connect(ho st, port)
File "C:\Python24\li b\smtplib.py", line 307, in connect
(code, msg) = self.getreply()
File "C:\Python24\li b\smtplib.py", line 351, in getreply
raise SMTPServerDisco nnected("Connec tion unexpectedly closed")
SMTPServerDisco nnected: Connection unexpectedly closed

Well that's useless. You could install a network sniffer
(http://www.ethereal.com/) and find out what's actually sent over the
network connection, and where things go wrong.
Have you verified that you are allowed to use SMTP on this server ?
Can you send email via it using outlook express or a similar POP3/IMAP
mail client?

:)
Sep 7 '06 #3
Sybren Stuvel wrote:
sridhar enlightened us with:
>>iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error
fromAddress = 's************* *@satyam.com'
toAddress = 's************* *@satyam.com'
msg = "Subject: Hello\n\nThis is the body of the message."

^^^^

You need \r\n\r\n there. Line-ends in email messages should be DOS
line-ends.
This is untrue for the Python smtplib, though correct according to the
RFCs. The SMTP.data() method uses a locally-declared function called
quotedata() to ensure the correct line endings, so using "\n" will
result in the same message as using "\r\n".
>
>>Traceback (most recent call last):
File
"C:\sridhar\B eginning_Python \Beginning_Pyth on\Chapter16\tr yitout\InitialM ailExample.py",
line 5, in ?
server = smtplib.SMTP("h stmsg002",25)
File "C:\Python24\li b\smtplib.py", line 244, in __init__
(code, msg) = self.connect(ho st, port)
File "C:\Python24\li b\smtplib.py", line 307, in connect
(code, msg) = self.getreply()
File "C:\Python24\li b\smtplib.py", line 351, in getreply
raise SMTPServerDisco nnected("Connec tion unexpectedly closed")
SMTPServerDis connected: Connection unexpectedly closed


Well that's useless. You could install a network sniffer
(http://www.ethereal.com/) and find out what's actually sent over the
network connection, and where things go wrong.
Useless it might be, but it's a lot more clueful than some questions we
see, so it seems a little dismissive just to say "it's useless" - the OP
has provided the traceback, which is so often missing in questions from
newbies, and has correctly localized the error to a small chunk of code.

True, the error message isn't particularly helpful in these
circumstances, but it probably represents an accurate description (from
the client's point of view) about what's happening, in which case an
Ethereal trace will provide little more data than the traceback. I
suppose it'll tell you whether the server is sending RST or FIN to
terminate the connection, but it won't give much insight into why.

We might hazard a guess that the connection is being closed because
there is no SMTP server running on the named host, or (less likely) it
requires authentication. Unfortunately when I try to connect to a
non-existent SMTP server on an existent host I see

socket.error: (113, 'Software caused connection abort')

under both 2.4.3 and 2.5b2. Alas I don't have ready access to a server
that requires authentication (my servers authenticate senders by POP
access IIRC). So I can't reproduce this error.

Perhaps the SMTP server is strapped down to accepting connections from
specific IP addresses by some firewall? It would probably be a good idea
to have a chat with the server's administrator to see if they can
suggest what might be going wrong.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Sep 7 '06 #4
sridhar wrote:
iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error
fromAddress = 's************* *@satyam.com'
toAddress = 's************* *@satyam.com'
msg = "Subject: Hello\n\nThis is the body of the message."
import smtplib
server = smtplib.SMTP("h stmsg002",25)
server.sendmail (fromAddress, toAddress, msg)

Do yourself a favor and use the email module to construct your messages
with. Constructing messages by hand can lead you into so many traps.
Especially if you are using international characters in you messages.
--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone: +45 66 11 84 94
Mobile: +45 29 93 42 96
Sep 7 '06 #5
Max M wrote:
sridhar wrote:
>>iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error
fromAddress = 's************* *@satyam.com'
toAddress = 's************* *@satyam.com'
msg = "Subject: Hello\n\nThis is the body of the message."
import smtplib
server = smtplib.SMTP("h stmsg002",25)
server.sendma il(fromAddress, toAddress, msg)

Do yourself a favor and use the email module to construct your messages
with. Constructing messages by hand can lead you into so many traps.
Especially if you are using international characters in you messages.

Good advice. However, since the error is occurring in the SMTP() call a
malformed message is clearly not the cause of this particular problem.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Sep 7 '06 #6
Steve Holden enlightened us with:
This is untrue for the Python smtplib, though correct according to
the RFCs. The SMTP.data() method uses a locally-declared function
called quotedata() to ensure the correct line endings, so using "\n"
will result in the same message as using "\r\n".
Ah, wonderful.
Useless it might be, but it's a lot more clueful than some questions
we see, so it seems a little dismissive just to say "it's useless" -
the OP has provided the traceback, which is so often missing in
questions from newbies, and has correctly localized the error to a
small chunk of code.
I agree with you. My remark might indeed have sounded harsher than
intended. It referred to the traceback itself, not the posting of the
traceback. That was rather useful.
Ethereal trace will provide little more data than the traceback.
I don't know until I see it. Perhaps the socket is closed in response
to something the client sends. That can be seen in the Ethereal trace.
I suppose it'll tell you whether the server is sending RST or FIN to
terminate the connection, but it won't give much insight into why.
A quick peek in the SMTP logfiles should tell you that.
Perhaps the SMTP server is strapped down to accepting connections from
specific IP addresses by some firewall?
In that case I'd expect the SMTP server to simply ignore the
connection attempt and cause a timeout in the connecting phase. I
wouldn't expect a connection to be created and then closed again,
which is what I read in the posted traceback.
It would probably be a good idea to have a chat with the server's
administrator to see if they can suggest what might be going wrong.
Good idea indeed. Another idea would be to use something like netcat
or telnet to connect to the port and see what happens if you manually
type an SMTP connection.

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Sep 7 '06 #7
Tim Williams enlightened us with:
Can you send email via it using outlook express or a similar
POP3/IMAP mail client?
Wouldn't you use a SMTP client to send email?

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Sep 7 '06 #8
On 07/09/06, Sybren Stuvel <sy*******@your thirdtower.com. imaginationwrot e:
Tim Williams enlightened us with:
Can you send email via it using outlook express or a similar
POP3/IMAP mail client?

Wouldn't you use a SMTP client to send email?
Outlook Express *is* a mail client that uses SMTP as the outbound protocol.

:)
Sep 7 '06 #9
On 2006-09-07, Sybren Stuvel <sy*******@YOUR thirdtower.com. imaginationwrot e:
Tim Williams enlightened us with:
>Can you send email via it using outlook express or a similar
POP3/IMAP mail client?

Wouldn't you use a SMTP client to send email?
I would, but I don't use exchange server. :)

The one exchange server I used in the past didn't accept SMTP
mail.

--
Grant Edwards grante Yow! I have the power
at to HALT PRODUCTION on all
visi.com TEENAGE SEX COMEDIES!!
Sep 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
394
by: Arek | last post by:
Hey, I have a question, what are the possibilities of sending emails using ASP.net. (and VB.net) What I think is that user can send automatic reminder if he check box on the form and submit. Do I need to have SMTP server? Can it be done without using of SMTP, something similar to automation in VB? I tried before for quite a few days to automate generating word documents and finally I gave up, so I would like to know before I start...
3
1590
by: A | last post by:
Hi all! I would like to ask a question on sending emails... I have a web application that requires sending emails using email templates. The templates that I've made are separate HTML files and would require some data based on what the user has entered. Please help!!!
4
4573
by: Nicole | last post by:
I found this code below to use to send emails using VB with Outlook. However, it gives these errors. 'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and 'Outlook.ItemEvents_Event'. Name 'olByReference' is not declared. Name 'olMailItem' is not declared. Name 'olTo' is not declared. How could i edit this code to get it to work?
4
3750
by: aroraamit81 | last post by:
Hi, I am using CDO component to send emails through my ASP page as I am having IIS on windows XP.......... Now the mails goes and gets into mailroot\Queue folder but does not reaches to the destination........ Pls tell me what do I need to do......... here goes my code for your reference.....
2
1249
by: Maxelcat | last post by:
HI I am really confused (and getting a bit stressed!!!) I want to send email from a form on the website I am developing. I have to use .asp (the host server doesn't have .net) After many hours I have got as far as this code:
3
1551
by: lizii | last post by:
Hey there - hopefully last newbie question i will ask for a while! I want my application to work where you click a button - and it either: a) open a email application - insert the correct email address and add a subject + any attachments or b) just create an email and send it off with appropriate attachments etc.
0
1780
by: damimkader | last post by:
Hi, I'm trying to send emails using a Macro based on an Excel Sheet and the Email Client I'm using is Lotus Notes. OS used - Windows Xp. Language - VB Below is the Code I'm using for doing the same. Dim Maildb As Object
1
1515
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, How can i send email to any email address using a specific email address or unknown email address.... Email may contain some attachments..... Thanx >> ALI <<
0
1291
by: Bernhard Walle | last post by:
Hi, * cindy jones : Following (tested) snippet should help: ------------------ 8< ------------------------------ from smtplib import SMTP from email.mime.image import MIMEImage from email.mime.text import MIMEText
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.