Thursday, July 9, 2009

Sending out email by python gaierror

I had to debug an instance of Plone that had an error to send out email today. First there was the whole problem with configuring sendmail to properly relay email. Finally I gave up, uninstalled sendmail and installed postfix.. :D Once I've verified the server can actually send email out, the problem still persist. It came to my mind that since the program (Plone) itself can send out email on other machines, it must be something else specific to that machine. Maybe python itself cannot send out email from that machine. So a quick google and I copied the code to send email out using python. It gave out the error more verbosely:

Traceback (most recent call last):
File "tryemail.py", line 24, in ?
server = smtplib.SMTP(SERVER)
File "/usr/lib/python2.4/smtplib.py", line 258, in __init__
addr = socket.gethostbyname(socket.gethostname())
socket.gaierror: (-2, 'Name or service not known')

Googling some more and I found this thread which basically says that python smtplib requires the hostname to be resolvable to send out email. So after some more googling (don't you just love google? :P) I found out how to change the hostname. So basically you need to change the HOSTNAME setting in /etc/sysconfig/network. But that requires a reboot. To avoid reboot just echo the hostname into /proc/sys/kernel/hostname. Finally. Now it's all done.. :)

1 comment:

Is Blogging No Longer a Thing?

As I embark on my new journey to learn the Rust programming language, I find myself pondering—where have all the blogs gone? In search of pr...