2

I am successfully performing some very basic SMTP sending in my machine with a basic Python script:

.... things ...

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, recievers, message.format(now, now))
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"

It works fine both in my machine and in a Ubuntu server I have in Virtual Box. Now I would like to send one email from one server using the other server as a host.

I tried in my virtual host to change

smtpObj = smtplib.SMTP('localhost')

with

smtpObj = smtplib.SMTP('IP of my PC') #IP get from "ifconfig -a"

but does not work.

Am I missing something?

  • refer this page unix.stackexchange.com/questions/82454/… – Rahul Patil Jul 10 '13 at 10:40
  • I get the same message both adding the IP or through IP in /etc/hosts as you suggest in your answer, @RahulPatil. Always socket.error: [Errno 111] Connection refused – fedorqui Jul 10 '13 at 11:42
  • Connection refused, means on remote machine port 25 is not running/open – Rahul Patil Jul 10 '13 at 11:48
  • also you can check tail -f /var/log/mail.log – Rahul Patil Jul 10 '13 at 11:51
  • @RahulPatil If I do nmap localhost -p25 I get the message 25/tcp open smtp. Is it right? Otherwise, how can I solve it? Many thanks. – fedorqui Jul 10 '13 at 12:01
3

It works fine both in my machine and in a Ubuntu server I have in Virtual Box. Now I would like to send one email from one server using the other server as a host.

As you mentioned it's working in both machine with localhost not with IP address of host then, might be mail server is running only on localhost, So you need to Bind Postfix Mail Server To all or specific IP Address to interfaces.

Postfix IP address bind configuration:

Open /etc/postfix/main.cf file

Append / modify line as follows to bind to localhost (127.0.0.1) only:

inet_interfaces = NEW_IP_ADDRESS,127.0.0.1

Save and close the file. You need to stop and start Postfix when this parameter changes. So type the following to restart Postfix:

/etc/init.d/postfix restart

If you are using sendmail:

Open /etc/mail/sendmail.cf

Find the line starting with DaemonPortOptions and then replace Addr=127.0.0.1 to Addr=0.0.0.0

Note: 0.0.0.0 means all active interfaces.

then restart sendmail and Verify that everything is working fine:

netstat -tulpn | grep 25
tail -f /var/log/maillog
  • Nice. Note, though, that I am using sendmail, not postfix. – fedorqui Jul 10 '13 at 12:43
  • I have updated for sendmail also. please check and let me know. – Rahul Patil Jul 10 '13 at 12:47
  • It worked! Now I can connect from one server to the other. smtpObj = smtplib.SMTP('the.other.ip.ip') works, although I am still getting some issues with the login part. – fedorqui Jul 10 '13 at 13:45
  • Well, now the problems I am facing are from Python, so the server part is successfully working. Thanks a lot for your help! – fedorqui Jul 10 '13 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.