Using Gmail or Google Apps email with Magento

May 24, 2009

I was asked this week by a reader about using Google Apps email with Magento. There are solutions available that will allow you to configure the Magento SMTP server settings, or even your linux server SMTP settings so that you can use Gmail or Google Apps email to send outbound emails with Magento. In this post I will quickly cover a simple little open source Magento extension I made that makes setting up Gmail and Google Apps Email child’s play.

The Google Apps and Gmail Magento extension

You might be wondering firstly why you would want to use Google Apps or Gmail for your outbound emails from Magento.

  • Easier to set up a stable, secure and robust solution than if you try to run your own SMTP server.
  • Easy to administer with either the Gmail or Google Apps interface. You can set up auto replies, and auto forwards.
  • Excellent search capability for finding messages that have been sent to customers.
  • Acts as a log or archive of all emails sent by Magento, which means you can make sure it’s not sending any you do not want sent, and easily track any that are sent.

So hopefully everyone knows how sweet it is using a hosted ‘in the cloud’ email service, now on to how to do it!

Installation

You can install the module from Magento Connect by getting the extension key. Then using your store backend Magento Connect manager, you’ll need to change your settings to accept alpha modules (on the settings tab) and then just paste in the extension key and click install. Too easy. You can change the alpha back to stable afterwards, by the way.

Configuration

The Module is configured in the System -> Configuration -> System section. There are only three things to choose, so it’s very easy to setup.

Using Google Apps or Gmail with Magento is made easy with my purpose built Magento extension.

Using Google Apps or Gmail with Magento is made easy with my purpose built Magento extension.

It’s hopefully redundant, but for completeness here is some documentation:

The Enable Google Apps Email option allows you to turn the extension on and off easily. When enabled the extension will use your supplied Google Apps or Gmail credentials to send email from the Magento store.

The Email Address field is where you type the full address of you Gmail account or Google Apps account. It is important you type the whole address, even for Gmail where you might be more familiar with just entering a username.

Finally the Password field is where you type you Email account password. There is currently no way to test the connection (i.e. to make sure you have the right password) but that is planned functionality for a later release.

The Technical Details

The module is very simple, it’s just two Model files that overwrite the email sending functionality with Magento.

The key is in the setup of the Zend transport object as shown below:

public function getGoogleAppsEmailTransport() {
 
	$email = Mage::getStoreConfig('system/googleappsemail/email');
	$password = Mage::getStoreConfig('system/googleappsemail/password');
 
	$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => $email, 'password' => $password);
	$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
 
	return $transport;
 
}

It’s annoying that for all the flexibility Magento allows, the way that the email sending has been coded really doesn’t allow much scope for extending the functionality without re-writing a sizable amount of Magento code. This means that maintenance becomes more difficult and the value of the inheritance structure is lost.

Setting up your Google Apps account

Sign up for a Google Apps account and then you’ll be able to create a ‘user’ to do your Magento email sending. In my current configurations I use email addresses like ‘mailer@xyzdomain.com’ or ‘no-reply@xyzdomain.com’. This means that to the end user the from email address will appear like a sophisticated CRM mailer, when in fact it’s just a free Google Apps account!

I also recommend setting the account up to forward a copy of all email to your own personal Gmail or Google Apps account. This way if any users do actually try to reply to the mailer address, the message will still make it to someone. If you wanted to you could even set up an auto responder that informed users to contact you in a preferred manner.

Feedback

I’d appreciate some feedback on this little module – I know the functionality exists elsewhere, but sometimes just making a good solution really easy for everyone, can be beneficial, hopefully you agree. If you spot any bugs or would like to suggest some new functionality, I’m all ears. Keen readers who check out the source code (which is totally open by the way) may notice I have some code in there for sending test emails, I just haven’t wired it up to the admin interface (backend) yet.

Ashley

Posts

Hi! I'm Ashley Schroder, a Software Engineer from New Zealand - this is a collection of notes on my experiences with Ecommerce Web Development, particularly Magento Development.

Are Your Customers Getting The Magento Emails You Send?

MageSend Magento Email sending with Amazon SES

I have made a premium Magento Extension called MageSend. MageSend makes it simple and easy to send using Amazon's highly reliable SES email service.

The extension is $99, and comes with a complete money back guarantee, please check it out, I am confident it will resolve any email sending problems with your Magento store.

142 responses to Using Gmail or Google Apps email with Magento

  1. @chx – that sounds like a hosting problem to me, check you don’t have a firewall blocking connectivity. Let me know.

  2. @Ashley — Thanks for responding.

    It turns out it was a problem created by one of the e-mail template extension which was declared as stable but didn’t support the magento version I am using.

    Lesson learnt: don’t take extension description for granted and do check out the respective support forum first.

  3. I’ve been using this extension for a while now and it’s worked perfectly. But all of a sudden, about 2 days ago it stopped working. I have no idea how it happened but while I get most emails- I do not get any emails sent by Magento, ie: contact form or copies of order confirms. I don’t know what to do! I tried to switch back to hosting my email with my web host but I can’t get any of the emails that I missed. Can you help me please?

  4. Can you run the self test please and post the output? Are you 100%, cross your heart and hope to die, sure that nothing changed, no upgrades, no new extensions, now changed passwords on the email account etc? Also enable logging and paste log output from several operations (self test, contact form etc)

  5. Aboslutely nothing changed but I tried uninstalling and reinstalling the extension and it started working again. Sorry bout that- I was getting reallly nervous. Thanks for responding – and thanks for a great extension!

  6. Hi ashley:

    worked beautifully..

    I’m switching to AWS now..

    problem with DNS stuff… load balancer is not quite working.. can’t get any ping message to come through at all..

    Anyway, thanks for the great work mate..

    cheers
    nathan

  7. Does this work with multi-domains, multi-website, Magento setups? Need to send from different emails and domains from different shops/websites.

  8. Yes, except in admin initiated emails (like admin added orders in the Magento backend) where the ‘store context’ is not correct. I’m looking at options to sort that out with Ben from Blue Acorn currently. Best bet is to try it with your particular setup and see if it meets your needs – if not let me know, because I use it for some multi-store setups, and if there are problems, I’d fix them.

  9. Hi Ashley,

    I installed your extension with the above instructions however when I run the self-test I get a 404 not found page.

    Any ideas?

    Regards,
    Simon

  10. Hi, Simon – That is strange, flick me an email with more details and if I get a spare 5 mins today I can have a look at your setup.

  11. Hi Ashley, firstly thank you by the extension, it’s pretty useful. :D
    I’m with a fresh 1.4.1.1 magento setup and i’d like know if your extension are working on it?

  12. Hi, Junio – you’re welcome! You could do me a big favor and install on 1.4.1.1, test it a little and post back here with the results, I haven’t had a chance to do it yet I’m afraid :)

  13. I’m on 1.4.1.1 but and have installed the extension however I cannot find it anywhere in the admin panel.

    As a matter of fact the heading ‘system’ does not exist under System > Configuration > ‘System?’ not sure if something has changed in this version or if I’m missing something.

    Please Advise.

  14. Sorry, please ignore my last comment, the extension appears under the advanced section down below, under System > Configuration > Advanced > System.

  15. Works wonders and i’m in love! Keep it up! Thanks for the great app.

  16. Hello. I Just Installed The Plugin And in the following test worked fine.

    But when i try to send a email to a friend in the store it simple doesn’t came.

    Can You Help?

    Thanks

  17. @Philipe Cardoso – try enabling logging and then paste the log output of simple test and also contact form, forgot password etc.

  18. Thanks a lot.

    The form i forgget my password works with your plugin on or off..

    But the newsletter doesnt work.

  19. Do you have other extensions installed? Check your log output during newsletter send.

  20. Hello Ashley!

    First of all, thank you for making this great plugin.
    I recently installed it on 1.4.1.1 and I’m getting a 404 error when I run the self test (for what I read in the comments, someone had the same problem).

    Can you help me out?
    Thank you!

  21. Hi Ashley,

    have seen your extension running in a older magento version, great stuff! But as Daniel i try get your 1.3.4 (beta) running on a magento 1.4.1.1. Selftest and Maillog end in 404. Even my smpt config values are not stored.

    Can you help us out please? Thank you!

  22. Hi Ashley

    I have earlier used your contribution.
    I have now installed Helpdesk Ultimate from Aheadworks, but it keeps sending out empty emails to me. I then ask support and this is the answer from them:
    Hi Morten,
    native Magento MageCore_Model_Email_Template is overridden by Aschroder_GoogleAppsEmail_Model_EmailTemplate that could not parse passed variables correctly.

    Is this correct? Does your script override some original magento templates? And if it does, how can i get the original templates back. I uninstalled your contribution, but it didnt work..

    I really hope you can help me…

  23. Hi, Morten
    Just to be clear the term ‘override’ in this context is the Magento extension capability to replace certain core functionality, not to actually change the core files at all.

    So yes, it does override, in fact most extensions that do _anything_ will override core functionality. It does not change any templates however, it overrides a Core class called Template.

    If you uninstall the extension (and clear your cache) then there will be no trace of the extension left behind (except an email log table). Once properly uninstalled you should not see this folder in app/code/Aschroder/SMTPPro and then your helpdesk extension will work as normal.

    You may not be able to actually send emails though (that may be why you installed my extension in the first place). In which case you either need to merge the capabilities of the extensions, or find an email solution that is compatible with the helpdesk extension.

    Hope that helps.

  24. I have installed the gmail extension and when i run the test i get a 404 error

    here is where it is pointing me
    http://www.emsstuff.com/index.php/admin/smtppro/log/

    This is what i have in the system log
    2010-12-21T20:50:38+00:00 WARN (4): AfA xmlrpc: (code 404) Not Found

    ANY thoughts

    Ron

  25. btw it does not generate an email at any point!!!

  26. hi, i just installed this extension because i couldnt send any emails and i have this problems.
    when running test this error appears

    ASchroder.com SMTP Pro Self-test results
    Testing outbound connectivity to Server:
    Using Google Apps/Gmail configuration options
    Connection to Host SMTP server successful.
    Sending test email to your contact form address mola*****@gmail.com:
    Unable to send test email. Exception message was: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘magento.smtppro_email_log’ doesn’t exist…
    Please check and double check your username and password.
    Contact Form test email did not use SMTPPro to send.
    Testing failed, please review the reported problems and if you need further help visit ASchroder.com to contact me.

    but in my inbox i find two emails “contact form” and “test email” so i thought it was working.
    i went to the frontend and tried to share a wishlist and this error appeared

    Cannot set standard header from addHeader()

    and no email anywhere

    could you try to help me please?

    big thanks

  27. @esteban Seems like two errors there. 1) the table did not get created, try uninstalling and reinstalling? 2) the headers error, I have had someone else report that, I’m not certain it is related to my extension, I’ll look into it more. I see that exception thrown in a Zend core class. Do you have any other email related extensions installed?

  28. his Asley.
    I used code above and confog in sytem :
    port: 587
    host: smtp.gmail.com
    but not work
    i used 1.4.1.1 ver

    Thanks

  29. @esteban
    I had same SQL error as you , found this thred via Google. I sorted it by changing permissions i.e. chmod 777 recursive, then log out / log in & let Ashley’s app do it’s stuff which is create the missing table.
    Tidy up the permissions afterwards as always.
    Hope this helps,
    Matt

  30. thanks for the replies. i sorted it out installing another extension

  31. When I try ‘Run Self Test’, I get the following:

    Testing outbound connectivity to Google:

    Connection to Google SMTP server successful.

    Sending test email to your contact form address the….@gmail.com:

    Unable to send test email. Exception message was: 334 UGFzc3dvcmQ6 …

    I’m pretty sure I’ve entered my account information correctly and I’ve tried several gmail / google apps accounts I have access to.

    Any idea what I’m doing wrong?

  32. Never mind. I didn’t realize I had to click ‘Save Config’ before running the Self Test.

  33. Not quite sure what to make of this error…

    ASchroder.com SMTP Pro Self-test results
    Testing outbound connectivity to Server:
    Using Google Apps/Gmail configuration options
    Connection to Host SMTP server successful.
    Sending test email to your contact form address support@happycow.com.au:
    Test email was sent successfully.
    Contact Form test email did not use SMTPPro to send.

  34. Hi, Justin

    It points to a possible extension clash – some other extension is controlling the email send. Check the contact form test email headers, if it is sent via Google then it is probably a false alarm.

  35. Hi,

    i have problem (maybe there are few of them)

    When I was using default magento sending system, client who buys a product receive an email, but I am (as owner) not receiving anything.

    Installed your extension (in manual way), filled fileds with google apps data but now there are no emails for client and not for owner (tried with contact form, with purchase orders).

    Tried to use smtp settings and filled google apps data, same problem continues

    Tried with another simple smtp data (not google apps) – same problem continues again.

    BUT when self-test are done (with google apps, smtp google apps and simple smtp data) everything looks good and I am getting test emails (test email and contact form example with your email).

    What I am doing wrong?

    Using magento 1.6.0.0, website is not in production state and all requests for that domain are redirected.
    My server (virtual dedicated) isn’t configured to send emails itself.

    Maybe there is a problems?

    P.S I have already used your extension in previous project and you helped me to solve another problem few months ago.

    I need your help now too, I am ready to make a donation for you work.

  36. Would this be a good fix or workaround for my magento installation not sending emails to my gmail apps account or do I have something else going wrong?

  37. Hi, and thanks for a nice extension!

    I wonder if its normal to get all sent messages in the gmail inbox to, not only in sent messages..

    Is there any settings that changes this?

    Thanks in advance,

    Johan

  38. I’m seeing the same issue as Johan—all emails sent are popping up in the sending account’s inbox as well. Any chance you’ve figured this out Ashley? Thanks :)

  39. Hy Ashley,
    It is not working. I am usinn magento 1.4.1.1 and your extension 1.4.3.
    I send you the test message, so eventually you can help me out fix it.
    Regards

    ASchroder.com SMTP Pro Self-test results
    Testing outbound connectivity to Server:
    Using Google Apps/Gmail configuration options
    Failed to connect to SMTP server. Reason: Connection refused(111)
    This extension requires an outbound SMTP connection on port: 587
    Sending test email to your contact form address puntel@shopfesta.com.br:
    Unable to send test email. Exception message was: Connection refused…
    Please check and double check your username and password.
    Contact Form test email did not use SMTPPro to send.
    Testing failed, please review the reported problems and if you need further help visit ASchroder.com to contact me.

  40. Hello, Ashley!

    Thanks for this amazing extension, it really do all the work for us on a blink!

    But I’m have a little issue, when I use my Gmail Apps account, my customer get the sent e-mail, but we don’t receive any bbc =/

    Could you help us showing the right direction, please?

  41. Do you have any plans to update this extension for compatibility with Magento version 1.7?

  42. It works perfect!

    I have to change one parameter on my configuration:
    Go to System -> Configuration -> System, Open Tab: SMTP Pro Email General Settings:
    Set “Choose extension option”: “Google Apps/Gmail”, and them It works.

    Thanks again! Good job!