One or the other reason we need configure the Mail Transfer Agent (Mail-server) to send and receive mail on the server. Lately I was working on one personal project where I wanted to send email update about any failure on the Amazon EC2 box. This EC2 box has ubuntu12.04 t1.micro instance for some light weight processing. I chose exim4 as a MTA, since I had used this in past and worked well with my python script to send email.
Run the following commands to install exim4

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install exim4
sudo dpkg-reconfigure exim4-config

once you execute the last command you will get following configuration window. You can pretty much accept the default options. The first configuration window asks you to mail server configuration. Select first option as shown in picture below becase we are going to send and receive email directly using SMTP.

exim4 1st configuration window

exim4 1st configuration window


The second window asks for the Fully Qualified Domain Name (FQDN). It populates the field by itself. In case, it doesn’t then execute the following command and put in the field.

/> hostname -A
your.FQDN.com
exim4 2nd configuration window

exim4 2nd configuration window

Provide the IP address where it should expect the SMTP connection. By default 127.0.0.1; ::1 is provided.

exim4 3rd  configuration window

exim4 3rd configuration window


For the below window you can provide the FQDN hostname and localhost.
exim4 4th  configuration window

exim4 4th configuration window


Since we don’t want to relay the email, we should leave this field blank.
exim4 5th  configuration window

exim4 5th configuration window


Just leave the field blank. Same as previous window.
exim4 6th configuration window

exim4 6th configuration window


Select “No” for this window and move ahead.
exim4 7th configuration window

exim4 7th configuration window


You can choose either of the options. For most of the configuration it will not make much difference. If you are using any kind of mail tool then select mbox option as shown in picture below.
exim4 8th configuration window

exim4 8th configuration window


Select the default option(NO) this will keep all the configuration in the same file. If you wish to separate the configuration file then select Yes. Once the set up is done the exim4 generates configuration file at /var/lib/exim4/config.autogenerated.
exim4 9th configuration window

exim4 9th configuration window

Note:
config.autogenerated file shouldn’t be touched. If you want to make any change then update the /etc/exim4/update-exim4.conf file and run "sudo update-exim4.conf" command.

Last but not the least, we need to check whether exim4 is correctly configured and able to send email. Execute the following command to test it.

echo "Exim4 mail-server test" | mail -s TestSub mail@code4refernce.com

You can change mymail@code4refernce.com to your email address. Check your email box after executing the command. You should receive email with Subject as “TestSub” and “Exim4 mail-server test” as content. If haven’t received any email in 2 mins then you should consider debugging exim4 for any configuration issue.

Debugging exim4

For debugging exim4, run the following command to check how many email are present in the queue.

/> exim4 -bp

25m  2.9K 0t5C6f-0000c8-00 <alice@wonderland.fict.example>
                             red.king@looking-glass.fict.example
                             <other addresses>

If this *** frozen *** appears at the end of the line that means the message is frozen because attempts to deliver it are suspended. In this case you should check the recipient’s address and look into mainlog file to find more clue about this problem. If the address is marked as D that means the message is already delivered to that address. If exim4 shows that the mail is delivered then check your junk mail-box.
exim4 log file is really helpful which is located at /var/log/exim4/mainlog. There are two more log files available write_rejectlog and paniclog. write_rejectlog contains entry about rejected email. paniclog contains entry for any serious service issue.

2013-07-02 03:49:41 1Utrb2-00081q-By => hamepal@gmail.com R=dnslookup T=remote_smtp H=gmail-smtp-in.l.google.com [173.194.79.27] X=TLS1.0:RSA_ARCFOUR_SHA1:16 DN="C=US,ST=California,L=Mountain View,O=Google Inc,CN=mx.google.com"
2013-07-02 03:49:41 1Utrb2-00081q-By Completed
2013-07-02 04:00:26 Start queue run: pid=30870
2013-07-02 04:00:26 End queue run: pid=30870
2013-07-02 04:30:26 Start queue run: pid=30885
2013-07-02 04:30:26 End queue run: pid=30885
2013-07-02 05:00:26 Start queue run: pid=30908
2013-07-02 05:00:26 End queue run: pid=30908
2013-07-02 05:30:26 Start queue run: pid=30924
2013-07-02 05:30:26 End queue run: pid=30924
Note:
For restarting exim4 you can use "sudo service exim4 restart" command.

If logfile doesn’t indicate anything and you still don’t receive the mail then check the EC2 Security group and make sure that you allow SMTP on 25 port. Run the following command to make sure that SMTP service is up and listening on port 25.

/> netstat -ano |grep :25

When I configured t2.micro(Ubuntu 12.04) instance then all ports were open and I didn’t face any problem. But it is always suggested to check the security group and define required rule.


Hope this blog helped you in some way. If you like this blog then please share it. You can also leave your comment below. You can find Facebook page here.

Related topics

  1. Simple python script to send an email
, , ,
Trackback

no comment untill now

Add your comment now