Re: sending emails using python




Brendon Towle wrote:
On Sep 7, 2006, at 3:50 AM, "sridhar"
<ramasridhar.kasturi@xxxxxxxxx>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 = 'sridhar_kasturi@xxxxxxxxxx'
toAddress = 'sridhar_kasturi@xxxxxxxxxx'
msg = "Subject: Hello\n\nThis is the body of the message."
import smtplib
server = smtplib.SMTP("hstmsg002",25)
server.sendmail(fromAddress, toAddress, msg)

error:

Traceback (most recent call last):
File
"C:\sridhar\Beginning_Python\Beginning_Python\Chapter16\tryitout
\InitialMailExample.py",
line 5, in ?
server = smtplib.SMTP("hstmsg002",25)
File "C:\Python24\lib\smtplib.py", line 244, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python24\lib\smtplib.py", line 307, in connect
(code, msg) = self.getreply()
File "C:\Python24\lib\smtplib.py", line 351, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
SMTPServerDisconnected: Connection unexpectedly closed


I saw a similar error when I was not following the server's
authentication protocol -- either failing to authenticate when it
wanted it, or authenticating when it didn't want it. Here's the code
I use -- tested on both an Exchange server and on Comcast's SMTP
servers. It assumes some globals (in all caps) which you need to set
first.

def emailGivenString(host=SMTP_HOST, fromAddr=FROM_ADDR,
toAddr=TO_ADDR, subject='', body='', auth=False):
server = smtplib.SMTP(host)
if auth:
server.login('username', 'password')
outMessage = 'From: %s\rTo: %s\rSubject: %s\r%s' %
(FROM_HEADER, TO_HEADER, subject, body)
server.sendmail(fromAddr, toAddr, outMessage)

If this doesn't work, I second the previous suggestion of talking to
the server admin.

B.

--
Brendon Towle, Ph.D. <Brendon@xxxxxxxxxxxxxxxx> +1-412-362-1530
"Debugging is twice as hard as writing the code in the first place.
Therefore,
if you write the code as cleverly as possible, you are, by
definition, not
smart enough to debug it." - Brian W. Kernighan



well, this type of authentication might work.Because the same process
of sending mail with authentication worked when i used java mail
application so iam confident of the same thing works in python also.

.



Relevant Pages

  • Re: sending emails using python
    ... if iam using the following code iam getting error ... server = smtplib.SMTP ... server.sendmail(fromAddress, toAddress, msg) ... I saw a similar error when I was not following the server's authentication protocol -- either failing to authenticate when it wanted it, or authenticating when it didn't want it. ...
    (comp.lang.python)
  • sending emails using python
    ... iam having user account on an exchangeserver. ... server = smtplib.SMTP ... server.sendmail(fromAddress, toAddress, msg) ...
    (comp.lang.python)
  • Re: Kerberos machine authentication - apparent authentication fail
    ... > until logon), the wireless connection can kick off when it is ready. ... > was confirmed in the server event logs with IAS (i set that up as the radius ... > as an ordinary user kicks in and takes over from the machine authentication. ... > while the network sorts itself out and a double click on a network link of ...
    (microsoft.public.windows.server.security)
  • Re: Basic Authentication + IIS 5 + Windows 2000 + Frontpage 2002 = failure?
    ... SYSTEM account. ... In IIS I took the virtual server that I was testing, ... Authentication premise. ... From a website perspective, I ...
    (microsoft.public.inetserver.iis.security)
  • Need help configuring Wireless Connection profile
    ... I have an SBS 2003 server and a Server 2003 member server set up using RADIUS ... Windows authentication for all users,4129,LRG\ryanv,4149,Wireless WPA2 PEAP ... Certificate Services ...
    (microsoft.public.windowsxp.general)