Purpose: So today we are going to learn how to configure the email relay server for your MediaWiki installation. There are many ways you can use the email feature in MediaWiki. We will take the simplest approach. But before we further dive into this topic we need to go over some basics of sending email in MediaWiki and in general in Linux.
MediaWiki & Sending E-mail
So if you have been following my MediaWiki posts so far you will notice that you are able to send emails to any public email accounts like gmail.com, hotmail.com, yahoo.com, etc. So you must be thinking that MediaWiki uses it’s own Email program to send out these emails, right? Well that’s not true. By default MediaWiki uses the popular MTA (Mail Transfer Agent), Sendmail, to send emails. Basically when you install MediaWiki, it configures itself automatically to use available MTA on the system, which in this case is Sendmail. So basically the entire process of sending emails through MediaWiki is transparent to you.
Problem Sending E-mails
AFAIU, Sendmail uses a default mail relay server on the Internet which sends out email to the desired email address. However, you may not want to use a Email server/router which resides on the Internet, rather you would like to use an Email server that resides on your internal LAN/Network which the Sendmail program (and in turn MediaWiki) will use to send emails.
So here is a set-up of my LAN (koolwal.net – an example) that I will use to explain rest of the tutorial. I have a Debian Lenny system with hostname wiki.koolwal.net, which runs the MediaWiki. Also I have a Windows Email server on my LAN, whose hostname is mail1.koolwal.net. Now I would like that the Sendmail program (and thus MediaWiki) uses my LAN Email server – mail1.koolwal.net – to send out emails instead of the default mail relay server (I don’t know which one it uses) that the Sendmail program uses.
So now let’s see how we can configure the Sendmail program in Debian…
Step 1: Edit Sendmail configuration file
Basically we are going to add a field called “SMART_HOST” in our Sendmail configuration file:
and add the following line near the beginnnig of the file:
Save and quit the file.
Please note the quote style (` and ‘). I suggest you copy the above line and paste it and then modify the name.
Step 2: Re-generate Sendmail configuration
Now in order to make our changes in Step 1 to take effect, we need to re-generate the Sendmail configuration file by the following command:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Optionally, you can also re-generate the above file, sendmail.cf, by these two command also:
make (or make -C /etc/mail)
as mentioned in the beginning of the sendmail.mc file. I haven’t tried the above two commands though.
Step 3: Re-start Sendmail
Just to be sure, it is a good idea to restart your Sendmail program:
That’s it. Now your Sendmail program and thus your MediaWiki will use mail1.koolwal.net as the email relay server to send out emails. You can confirm this by looking in your log files:
# tail /var/log/mail.info
Oct 14 23:26:54 wiki sendmail: n9F6Qsvh021214: from=www-data, size=665,, nrcpts=1, msgid=<200910150626.n9F6Qsvh021214@wiki.koolwal.net>, relay=www-data@localhost
Oct 14 23:26:54 wiki sm-mta: n9F6QsVs021215: from=<email@example.com>, size=914,, nrcpts=1, msgid=<200910150626.n9F6Qsvh021214@wiki.koolwal.net>, proto=ESMTP, daemon=MTA-v4, relay=localhost.localdomain [127.0.0.1]
Oct 14 23:26:54 wiki sendmail: n9F6Qsvh021214: to=Kushalk <firstname.lastname@example.org>, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30665, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (n9F6QsVs021215 Message accepted for delivery)
Oct 14 23:26:54 wiki sm-mta: n9F6QsVs021215: to=<email@example.com>, ctladdr=<firstname.lastname@example.org> (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=120914, relay=mail1.koolwal.net. [192.168.0.3], dsn=2.0.0, stat=Sent ( <200910150626.n9F6Qsvh021214@wiki.koolwal.net> Queued mail for delivery)
Still having problems?
If you are still having problems sending emails through the new defined email server, I suggest that you configure your mail server (mail1.koolwal.net) to accept emails from your Debian system (wiki.koolwal.net) running MediaWiki. You can probably add the IP-address of your Debian system to the allowed list.