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. Very good idea. nice work and exactly what I am looking for!

  2. sounds like a useful extension, and I am going to install and test it as I use Google Apps with the domain of a website I am building using magento. so will leave so feed back and can help test this.

  3. This extensions sucks and does not work! Fuck you for creating it and fuck you for making me try and get it to work

  4. Thanks for the constructive feedback, I’m sure the open source community is richer for your involvement. If you’d like to describe the problem, I could help you fix it.

  5. Ashley,

    I installed your module on my staging site earlier in the week and it worked just beautifully. Thank you for all your work in making this available! By the time (a day or two later) I moved forward and installed it on my production site, it appears you had released a new version β€” one with “Use store email addresses” available. I like the idea of this new feature.

    Unfortunately, however, the module doesn’t seem to work at all on my production site, with or without “use store email addresses” enabled. Since the last version worked on an identical site, I suspect the problem is somehow inherent to the changes made. I hope that knowing this will somehow help you in future development of the module.

    In the meantime, is it possible for me to install the previous version?

    Thanks again. I admire and appreciate the contributions you’re making as a developer to the open-source community. Magento wouldn’t be all that useful to the rest of us without you and others who share your spirit.

  6. Also, it may be of use to you to know that when Google Apps does attempt to send an email with the current code installed (which seems to be only sometimes, as I frequently see no activity at all), the emails all seem to be returned with the following error. It may in fact be related to the recipient domain and not the module, but I thought it bore reporting, since the emails sent from the local mail server get through to the same recipient domain without interruption, and it’s only the ones sent through Google Apps that are returned this way. Again, not a problem with the previous release.

    β€”β€”

    Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 501 501 Malformed RCPT TO: – psmtp (state 17).

  7. You know, after a bit more experimenting, it appears that the reason it wasn’t working at all might have had something to do with the hyphen in the email address I was using. I’ve switched it over to one without and it seems to have made a huge difference. Now only the recipient domain thing is an issue, which I expect probably has nothing to do with your module. So thanks again!

  8. Thanks for the feedback, I’ve sent you an email requesting a bit more info, hopefully if it is a problem with the extension I can get it ironed out.

  9. Do you have an error reporting yet? I have this installed and properly setup but when trying anything that sends email it times out and no email is sent. I’d like to see if I can figure out where the problem is. Does this work in 1.3.2.1? Thanks.

  10. Hi,

    Thanks for trying our my extension. Error reporting/logging is planned for the next release (in a few days) – which will also see the extension tested on 1.3.2.1. As for idnetifiying the problem. Timeouts tend to be caused by firewalls blocking outbound SMTP. If you have ssh access to your host please try:

    telnet smtp.gmail.com 587

    And paste the results back here, it might show what is happening.

  11. Here are the SSH results

    Trying 209.85.147.109…
    Connected to smtp.gmail.com.
    Escape character is ‘^]’.
    220 mx.google.com ESMTP m34sm9823968waf.21

  12. Finally found the info I needed thanks to your great blog, thanks! ^^

  13. I installed. I try both gmail and my apps domain email. Testing on both is the same.


    ASchroder.com Google Apps and Gmail Self-test results
    Testing outbound connectivity to Google:
    Connection to Google SMTP server successful.
    Sending test email to your contact form address lingo@lingoteca.com:
    Unable to send test email. Exception message was: 334 UGFzc3dvcmQ6 …
    Please check and double check your email and password. If in any doubt you can login to the web interface for your email address to confirm at either ‘mail.google.com/a/your_domain’ or ‘gmail.com’.
    Testing failed, please review the reported problems and if you need further help visit ASchroder.com to contact me.

  14. Hi,

    Thanks for trying my extension, have you tried logging in to both accounts using the web interface? Perhaps you got the password wrong and now Google wants you to login to the web interface and solve a captcha to prove you are a human! Otherwise let me know what happens when you try to login through web interface and we can go from there.

    Cheers,
    Ashley

  15. Ignore my previous message. Testing worked. I was running a test before saving configuration. So first thing Save Config then Run Self Test. So installing and testing your extension worked out just fine.

    Now, the problem I am having: somehow when I test the Contact us form, or when I send in an order – admin does not receive any emails. The store owner does not receive and email. Store buyer does receive an email. Any thoughts? Thanks, Fatos

  16. I’ll make that clearer in the next release, thanks for pointing it out. Re: the emails not comin to you, have you configured the appropriate email addrsses in the magento backend?

  17. Hi,

    I installed your extension in my domain – dzipars.lv/magento and it worked like a charm for 2-4 days πŸ˜€ and wolla – nobody get e-mails from day 5. I have ssh acces to server and use Ubuntu Linux 9.04, maybe you can suhhest something and contact me via horninc@gmail.com?
    Ps: test works, no ordinary e-mails are sent.

    TY

  18. Hi! I just wanted to thank you for sharing such an excellent contribution with the Magento community.

    Your extension works flawlessly, and it helps to solve a big problem.

    Best regards,
    Marcus

  19. Hi, Marcus

    Thanks for the feedback, I appreciate it. If there are any features you think would be useful, please let me know – I’m always looking to improve the extension.

  20. Thank your for your ext, It ‘s very lovely.
    But Now, I can’t download via connect, please send me via email.
    Thanks

  21. Hello Ashley, Thank you for great extension! I am using it for all outgoing emails and also for newsletter and here I come to a problem with gmail’s limitation of number of sent emails. I got “You have reached a limit for sending mail” message from gmail. Can you help me on how can I limit number of newsletter messages sent per cron job please?

  22. Hi,
    If I have time I’ll look into this in more detail, but it seems if you want a quick fix you should look at the function: sendPerSubscriber in app/code/core/Mage/Newsletter/Model/Queue.php which is called from at least a couple of places: app/code/core/Mage/Newsletter/Model/Observer.php and app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php. I might try and add some configuration for the parameters to an extension – though it seems judging by the source code comments, that configuration around sending is planned.

    If you do make some changes, please let me know I might be able to merge a patch in to help out others with the same problem.

    Cheers,
    Ashley

  23. After I Installed your extention it totally changed the look and feel of the website and added more to every page…. How do I change this back to the design we created???? I need to know ASAP as this functionality was not something I read about in your descriptions and it totally messed up the whole site!!!

  24. I installed everything and the test works fine (connects and sends) to the gmail account, but none of the other emails work. I checked and double checked the Store Email Addresses. Enabled and Disabled the Send Using the Store Email Addresses. Nothing works.

    Please help?!

  25. Enable logging in the Magento admin and check out the log file, my extension will log what it’s doing and that should help find out why the test works and the actual emails do not.

  26. Dear Ashley,

    I use magento version 1.3.2.3 and I installed this extention and then I went to System – Configuration – System.
    In our blog you have said that there are only three things to choose whereas I get four choices which are –
    (i) Enable Google Apps Email
    (ii) Use Store Email Addresses for Reply-to
    (iii) Email Address
    (iv) Password

    I filled in all these choices, and used my mail id sales@syberplace.com which was given to me by google.

    On clicking the self test button I get this message –

    ASchroder.com Google Apps and Gmail Self-test results
    Testing outbound connectivity to Google:
    Connection to Google SMTP server successful.
    Sending test email to your contact form address sales@syberplace.com:
    Unable to send test email. Exception message was: 334 UGFzc3dvcmQ6 …
    Please check and double check your email and password. If in any doubt you can login to the web interface for your email address to confirm at either ‘mail.google.com/a/your_domain’ or ‘gmail.com’.
    Testing failed, please review the reported problems and if you need further help visit ASchroder.com to contact me.

    Can you guide me on how I can fix this problem and make this extension work.

    Thanks
    Shailin

  27. Did you try to log in using the web interface, I have seen that error when Google is trying to present a CAPTCHA to prove you are a human. Let me know if that helps.

  28. Hi Ashley,

    I get the same error as shalin. I use google apps for email. I have checked the user interface that the account is active(went through the captcha activation). Is there any guidance you can provide?

    Thank You:)

  29. Hi, Gil

    I can’t replicate the error with my Google Apps accounts, if you trust me enough you could flick me an email with your username/password and I’ll see if I can replicate the error with your credentials on my test store. If I can then maybe I can figure out what’s wrong. Send me and email or use my contact form if you’d like to give it a try.

    Cheers,
    Ashley

  30. been trying to use the extension but bluehost does not support 587 i tried changing it in the code to 2526 or 465 and no luck. still get an error. can you please help me out.

    Thanks in advance,
    Kris

  31. Sorry mate, that port isn’t chosen for it’s numerology, Google specifies the port, we just have to connect to it. You need to ask you host to stop being so restrictive! Or just get a better Magento host

  32. Hello Ashley, is it possible to disable the google mail for contact form only?

  33. Hi, Not without code modification. You could test for reply-to being set and to=contact form address to and then return super class result, rather than running my method? Can I ask why you want to do that?
    Cheers,Ashley

  34. Shailin & Gil,

    I had the same error. Fatos had the answer for me… that you need to save the config settings before running the self test.

  35. Sorry, that’s catching a few people out now. I’ll add a note under the button in the next release πŸ™‚

  36. Hello, first of I have to tell you that, I am new to Magento and I am still testing in on my local windows server.

    This is what I get, when I run the self test(both with Enable/Disable Google Apps Email, since I still don’t have Google Apps Email acc),
    using a valid gmail address:

    ASchroder.com Google Apps and Gmail Self-test results
    Testing outbound connectivity to Google:
    Connection to Google SMTP server successful.
    Sending test email to your contact form address hello@example.com:
    Unable to send test email. Exception message was: Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto
    Please check and double check your email and password. If in any doubt you can login to the web interface for your email address to confirm at either ‘mail.google.com/a/your_domain’ or ‘gmail.com’.
    Testing failed, please review the reported problems and if you need further help visit ASchroder.com to contact me.

    Is this error rΠ΅lated with the fact, that I am using local windows server, or that I don’t have a G Apps Email account?

    Should I change something in the System -> SMTP setting (only for Windows Server)?

  37. Hi, I Google’d your error and got this thread about HTTPS proxying with Zend. Maybe this relates to your issue? Also the google apps/gmail extension is for use with either an apps account or a gmail account, do you have either of these? If not you should use my SMTP Pro Magento extension. Cheers, Ashley

  38. Hi, thx for the response.

    I still don’t have a Google apps account, that’s why I don’t enable it, and I am using a valid Gmail address, since I have a gmail account.

    I am going to check the 2 links, that U have posted.

    Thx again.

  39. I have just enable the openssl.dll in the php configuration file, and everything works perfect now.

    TY and keep up the good work.

  40. Hi thanks for the app but I am having some trouble. Any help would be great. I put in my working apps account info@mindgamesonline.com.au and my password but I get this error when I run the test. Thanks for any help

    ASchroder.com Google Apps and Gmail Self-test results
    Testing outbound connectivity to Google:
    Failed to connect to Gmail SMTP. Reason: Connection timed out(110)
    This extension requires an outbound SMTP connection on port 587. You need to check if your hosting server blocks outbound TCP connections or SMTP connections on port 587, and if so request access. If you are sure your host supports outbound SMTP on port 587 then something else is preventing a test connection. Please visit ASchroder.com for more information.
    Sending test email to your contact form address info@mindgamesonline.com.au:
    Unable to send test email. Exception message was: Connection timed out…
    Please check and double check your email and password. If in any doubt you can login to the web interface for your email address to confirm at either ‘mail.google.com/a/your_domain’ or ‘gmail.com’.
    Testing failed, please review the reported problems and if you need further help visit ASchroder.com to contact me.

  41. Hi, Ross

    The key in that test result is this:
    “This extension requires an outbound SMTP connection on port 587. You need to check if your hosting server blocks outbound TCP connections or SMTP connections on port 587, and if so request access. If you are sure your host supports outbound SMTP on port 587 then something else is preventing a test connection. Please visit ASchroder.com for more information.”

    And even more key in particular:
    “You need to check if your hosting server blocks outbound TCP connections or SMTP connections on port 587, and if so request access”

    Have you contacted your host about this? You should first confirm that port is able to be connected to. If not, then you should get a better Magento host πŸ™‚

  42. Thanks working now. Love your work.

  43. Ashley,

    Thanks for your support in the community. I’ve tried a bunch of your extensions and you put up some truly extraordinary work!

    With that said, I have a question to ask πŸ™‚

    I was hoping I could use this extension to modify the signature line of the emails being sent out: more specifically, I want to add payment information to the Send Order Email Copy To section of the Sales Emails.

    So to recap, an order confirmation email is sent to the customer upon purchase; I would like a copy of this email sent to my supplier with billing information in a signature line, but so far, I cannot find a way to add this. I’ve tried my hosting provider’s Forward and Auto-Responder solutions, but to no avail.

    I no this isn’t necessarily the function you were looking to get out of this extension, but I figured you may be able to point me in the right direction.

    If you might help with where I can enter additional information only to the extra sales copy (even if it’s hard copy payment information, that will be awesome), I’d greatly appreciate any help you can give me.

    Thanks again,

    Dibears

  44. I get the following error with version 0.5
    Unable to send test email. Exception message was: 553-5.1.2 We weren’t able to find the recipient domain. Please check for any …

    any help you can provide is appreciated – thank you for this module, I hope to get it working asap.

  45. That looks like your google account is rejecting the email because the to: address is no good. The to: address for test emails is your contact form address. Check your contact form address is a) set up and b) not got any typos in it.

  46. that was it I had it there wrong.

    thank you!!!!!

  47. sorry 1 more question – the test works great but when someone orders something from the store its still trying to use the postfix

  48. Hi, Hmmm – Is the extension enabled? Have you got another one that might be conflicting?

  49. you were right! I had your SMTP program on there.
    thanks again!

  50. Ashley,

    I’ve installed v0.5 of the Google Apps/Gmail and am getting a 404 when I try the self test. I’ve read all the posts and see that people were having trouble when not saving the settings first. That’s not my problem.

    I’m on Magento 1.3.2.4. Has it been tested on 1.3.2.4?

    Kevin