Sunday, August 7, 2011

SMTP on Macbook with VirginMedia

After upgrading to Lion PostfixEnabler no longer worked, so I had to do this by hand. It was less than straight forward. Cudos to the following pages for pushing me in the right direction:

  • http://cloughnet.org/jeremy/linux/postfix/relaying-to-an-email-server-using-tls-wrapper-mode/
  • http://marc.info/?l=postfix-users&m=123799751204881

Virgin Media's SMTP server uses SSL on port 465. For reasons I don't care to understand, this is deprecated, and not supported by Postfix. Therefore, to use this we have to setup a secure tunnel using stunnel, and then get postfix to use the newly created stunnel as a relay.

Stunnel is already installed on Lion (as stunnel3). As I didn't realise this until after the event, I built stunnel from source my self:
  • Install XCode (required for 'make')
  • Go to the stunnel website
  • Get latest source
  • Extract to disk
  • Following stunnel build instructions
  • Put any old stuff in the generated certificate
Add the following to the stunnel.conf file in the root of the source

[smtp-tls-wrapper]
accept = 11125
client = yes
connect = smtp.ntlworld.com:465

Fire stunnel up with this config check there are no errors
sudo stunnel stunnel.conf
Before configuring postfix, we need to stop OS X from getting involved (for reasons why, see here). Edit the org.postfix.master.plist file in /System/Library/LaunchDaemons (as root or using sudo) and add the following two tags within the <dict> container:
<key>Disabled</key>
<true/>

Then Restart your Mac.

Finally, configure postfix. Add the following to the end of /etc/postfix/main.cf
myhostname = davidatkins.co.uk
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = localhost.localdomain, localhost, 127.0.0.1
relayhost = [127.0.0.1]:11125
mynetworks_style = subnet

Note the relayhost to stunnel.

You should then be able to send mail:
echo "hello" | mail -s "subject" dave@davidatkins.co.uk
You can view the postfix logs in /var/log/mail.log
tail -f /var/log/mail.log

Note that once you've done this you'll need to manually start postfix and stunnel after every reboot to send mail.

No comments:

Post a Comment