August 30, 2011

259 words 2 mins read

Configuring MediaWiki to use external SMTP

At my new company, I setup a copy of MediaWiki and wanted to make sure that all the notifications work. One kink was that the mail needed to be sent through an external service called SendGrid. Since I setup MediaWiki and it is for internal use only, I could probably have skipped the email service but it seemed like a good exercise. Fortunately, MediaWiki has the capability to do this and it isn’t terribly difficult.

First thing you want to do is install PHP’s

PEAR Mail. If you’re on Ubuntu/Debian, it’s super simple:

  • sudo -s
  • apt-get install php-pear
  • pear install mail
  • pear install Net_SMTP
  • pear install Auth_SASL
  • pear install mail_mime
  • /etc/init.d/apache2 restart

Now you need to add/configure MediaWiki’s $wgSMTP variable in your wiki’s LocalSettings.php file, an example is show here:

<br /> $wgSMTP = array(<br /> 'host' => "", //could also be an IP address<br /> 'IDHost' => "",<br /> 'port' => 25,<br /> 'auth' => true,<br /> 'username' => "my_user_name",<br /> 'password' => "my_password"<br /> );<br />

If you don’t need to authenticate yourself, change ‘auth’ to false and drop the username/password options. Otherwise you should be able to get right onto the wiki and start emailing yourself through your 3rd party mail system. If you have any issues, just set $wgShowExceptionDetails = true; in your LocalSettings.php file and try your request again. As for myself, the configuration to SendGrid (which offers a “free plan” with 200 messages a month) was painless and works flawlessly. Now I know my messages will get delivered and have DKIM and DomainKeys!