Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Using an external SMTP server (Gmail) to send mail

Go to End

2 Posts   19941 Views


Community Member, 283 Posts

19 September 2009 at 4:29am

Edited: 19/09/2009 7:44am

For those that are having external SMTP mail issues, like the post titled "Using PHPMailer to send emails from external SMTP"

There is a better way to solve this! DON'T MODIFY SS CORE FILES! This is never a good idea for many reasons. Fix your php mail() function to send via a relay instead.

This is exclusive to linux servers. I'll be presenting No Brainer SMTP (nbsmtp) here, a good alternative is Simple SMTP (sSMTP). I will be using Gmail as an example here as it seems to be a common ask.

What you need here is a MTA to send via an external SMTP server that supports SMTP_AUTH. SS currently (as of 2.3.3) can only take advantage of the php mail() function which passes through to sendmail on linux. Instead of hacking the source code per above give this a shot if you have some kind of admin rights over your server:

Step 1: Fix your MTA
-Install nbsmtp ( ) or ( )
This is a lightweight MTA that simply passes sendmail through to a relay. It is available for Debian Ubuntu RHEL and CentOS. It will install a link to /usr/sbin/sendmail that will be used by all apps that default to sendmail (If this concerns you see the Edit: below)

Step 2: Configure
-Option 1: Configuration via php's sendmail_path, set with ini_set() or by editing your php.ini

sendmail_path = sendmail -N -n -f -h -d -p 25 -U -P myPassWord

-Option 2: Create a system-wide config for nbsmtp (usually /etc/nbsmtprc). This is a bit more secure as your password is in a root owned file that can be locked down.

relayhost =
port = 25
domain =
auth_user =
auth_pass = myPassWord
auth_mech = login
# You may need to set these to false if your installed version of nbsmtp wasn't compiled with SSL/TLS support
use_tls = true
use_starttls = true

Step 3: Test
Give it a test from the cli with either sendmail alone or from php -r.

dalesaurus@hostname:~$ sendmail -f
Subject: nbsmtp test
I hope all is well?

dalesaurus@hostname:~$ php -r 'mail( "", "nbsmtp test", "I hope all is well?");'

If nothing happens tail -f your logfile (usually /var/log/mail.log) and try again. It may help to enable debugging with -D (Option 1) or debug = 1 (Option 2).

Step 4: Relax
Pop a cold one, you're done. A little bit of admin work beats hacky coding any day. Bonus! You didn't have to change up your SS core files and use custom functions, so you can upgrade SS without any worries in the future.

nbsmtp is a MUCH simpler option than configuring a SMARTHOST with standard sendmail MTAs. Trust me. I've done it both ways :)

EDIT: You may not want to change whatever default MTA your server is setup to use with sendmail. There is no telling what kind of hell you may unleash if you 'apt-get remove sendmail' or 'yum remove sendmail' before Step 1 above.

If this is the case you should manually compile/install nbsmtp and call it directly instead of having it hijack your default /usr/sbin/sendmail. Then replace all the above 'sendmail' commands with 'nbsmtp'.

EDIT 2: If you do end up use sSMTP here is a good resource that covers Gmail:


Community Member, 283 Posts

15 December 2009 at 9:00am

Also after using some other relay mailers I have settled on msmtp as it has better support/documentation and is being actively developed. The configuration is the same methods as above (global config file or on the CLI via the sendmail line in the php.ini).

Install Guide:

For Gmail: