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?

10
  • refer this page unix.stackexchange.com/questions/82454/… Commented Jul 10, 2013 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
    Commented Jul 10, 2013 at 11:42
  • Connection refused, means on remote machine port 25 is not running/open Commented Jul 10, 2013 at 11:48
  • also you can check tail -f /var/log/mail.log Commented Jul 10, 2013 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
    Commented Jul 10, 2013 at 12:01

1 Answer 1

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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .