problems with smtplib

J

Jon Hewer

hi

having a few problems sending an email with smtplib. i do have an
smtp server running on port 25 of my local machine

here's the relevant code (taken from python docs):

s = smtplib.SMTP('localhost')
s.connect()
s.sendmail(me, to, msg.as_string())
s.close()

and i'm getting this error:

Traceback (most recent call last):
File "pysendmail.py", line 31, in ?
s = smtplib.SMTP()
File "/usr/lib/python2.3/smtplib.py", line 254, in __init__
addr = socket.gethostbyname(socket.gethostname())
socket.gaierror: (-2, 'Name or service not known')

if i don't sepcify 'localhost' i get the same error

if i specify the port and local_hostname too

class SMTP([host[, port[, local_hostname]]])

then my script just freezing at some point trying to connect/send and
the email doesn't get sent

if anyone can help that would be great...

jon
 
H

Harlin Seritt

What are you getting in your smtpd logs? Are you using postfix?
sendmail? or are you running this against a Windows stmp service?

Harlin Seritt
Internet Villa: www.seritt.org
 
N

n00m

I also can't get my SMTP (win2k) working with Python.
But... funnily this works fine:

import smtplib
s = smtplib.SMTP('smtp.mail.ru')
s.sendmail('(e-mail address removed)', '(e-mail address removed)', 'hi
there!')
s.quit()

Why do they (mail.ru) allow outsiders to use their service???
 
S

Steve Holden

n00m said:
I also can't get my SMTP (win2k) working with Python.
But... funnily this works fine:

import smtplib
s = smtplib.SMTP('smtp.mail.ru')
s.sendmail('(e-mail address removed)', '(e-mail address removed)', 'hi
there!')
s.quit()
That's pretty strange: the second argument should be a list. Are you
*sure* it worked?
Why do they (mail.ru) allow outsiders to use their service???
Ask them!

regards
Steve
 
N

n00m

Steve said:
That's pretty strange: the second argument should be a list. Are you
*sure* it worked?

Hmm...
I sent a couple of letters to my two different addresses... and got
them!
 
P

Peter Hansen

Steve said:
That's pretty strange: the second argument should be a list. Are you
*sure* it worked?

No longer required (as of at least Python 2.3 if not earlier).

"to_addrs : A list of addresses to send this mail to. A bare string
will be treated as a list with 1 address." (from smtplib.py sendmail()
docstring)

-Peter
 
S

Steve Holden

Peter said:
No longer required (as of at least Python 2.3 if not earlier).

"to_addrs : A list of addresses to send this mail to. A bare string
will be treated as a list with 1 address." (from smtplib.py sendmail()
docstring)
Oops. Documentation bug. Fortunately it looks like it's been fixed in
response to bug 1217513. Thanks for the tip, Peter.

regards
Steve
 
J

Jon Hewer

just got home and i've tried my script on windows with my isp's smtp
server, and found that my code wasn't getting past the s.connect()

changed me code to:

s = smtplib.SMTP('smtp.lineone.net')
s.sendmail(me, to, msg.as_string())
s.quit()

and now it works fine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top