sSMTP and Office365
Firstly I had to get sSMTP installed and talking nicely to our Office365 SMTP server. Step one – install sSMTP.
sudo apt-get install ssmtp
I got messages about
php.ini being modified … I chose to keep the local version, since it had extra stuff added that I needed. If you haven’t touched your
php.ini file, just install the package maintainer’s version.
Then I edited
Note that you’ll need to get your own Office 365 SMTP config settings which might be different to mine. To find them, log in to Outlook Web Access (ie Outlook in the browser) and click the settings cog at the top right, then Mail. Then in the menu that appears on the left, click Accounts -> POP and IMAP, and take note of the settings in the SMTP section.
Note also that this contains your real Outlook password. I’ve decided that’s OK for a Vagrant box on my PC that nobody else can get to … you need to determine your own security arrangements.
Note also that you need to use your username in some places and your real email address in other places. And it needs to be your address – the one for the username and password you’re using – otherwise Office365 will think you’re pretending to be someone you’re not, and it will refuse to deliver the mail.
And I’ve removed all the comments for this post – but of course there’s no harm leaving them in if you want to.
Check that sSMTP is working
Before you move on to PHP, it’s worth checking that sSMTP is working. So enter this at the command line to send a test email:
echo -e "From:firstname.lastname@example.org\nSubject: From sSMTP\n\nThis is a test email." | ssmtp -d email@example.com
firstname.lastname@example.org with your real address (or Office365 won’t accept the email), and replace
email@example.com with the address you want to send the email to. If it’s all set up correctly, there should be a new email in the recipient’s inbox.
Getting PHP to use sSMTP instead of sendmail
This requires editing your
php.ini file – and if you have several, you need to edit the one that PHP is actually using. I temporarily added a
phpinfo() page to my PHP app to see which
php.ini file was being used, and for me it was
So find the right
php.ini file and change this line:
sendmail_path = /usr/sbin/ssmtp -t
…and try sending an email from your PHP code.
Working – but slow
Email is now working, but it goes very slowly. That might be because the hostname needs to be a fully qualified domain name for mail to send smoothly. So the last thing I did was to edit
/etc/hosts to change the first line and changed the hostname in
Though of course Vagrant then changed the hostname back as soon as I halted and brought it back up again, so I then went to
C:\Vagrant\[myVagrantBox]\scripts\homestead.rb on my host machine and changed
config.vm.hostname = settings["hostname"] ||= "homestead" to
config.vm.hostname = "myproject.app".
But this didn’t help much. So email is still slow. 😦 But it works, so I’m going to leave it for now.
Still to do…
This is now working fine for me, but if I ever have to re-build my Vagrant box, I’ll have to do this setup all over again. Which is not the way Vagrant is meant to work.
So my next step will be to include this in a Vagrant script … once I re-check the syntax on moving files and work out what to do about the password.