By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

problems with smtplib

P: n/a
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
Sep 2 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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

Sep 2 '05 #2

P: n/a
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('n**************@mail.ru', 'jonhe...@gmail.com', 'hi
there!')
s.quit()

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

Sep 2 '05 #3

P: n/a
n00m wrote:
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('n**************@mail.ru', 'jonhe...@gmail.com', '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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Sep 2 '05 #4

P: n/a

Steve Holden wrote:
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!

Sep 2 '05 #5

P: n/a
I'm running Fedora Core 3, and I assume thats useing sendmail...

On 2 Sep 2005 04:25:41 -0700, Harlin Seritt <ha**********@yahoo.com> wrote:
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

--
http://mail.python.org/mailman/listinfo/python-list

Sep 2 '05 #6

P: n/a
Steve Holden wrote:
n00m wrote:
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('n**************@mail.ru', 'jonhe...@gmail.com', 'hi
there!')
s.quit()

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
Sep 2 '05 #7

P: n/a
Peter Hansen wrote:
Steve Holden wrote:
n00m wrote:

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('n**************@mail.ru', 'jonhe...@gmail.com', 'hi
there!')
s.quit()


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)

Oops. Documentation bug. Fortunately it looks like it's been fixed in
response to bug 1217513. Thanks for the tip, Peter.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Sep 2 '05 #8

P: n/a
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

On 9/2/05, Steve Holden <st***@holdenweb.com> wrote:
Peter Hansen wrote:
Steve Holden wrote:
n00m wrote:
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('n**************@mail.ru', 'jonhe...@gmail.com', 'hi
there!')
s.quit()
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)

Oops. Documentation bug. Fortunately it looks like it's been fixed in
response to bug 1217513. Thanks for the tip, Peter.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

--
http://mail.python.org/mailman/listinfo/python-list

Sep 2 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.