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.
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.
I can confirm v0.5 of the Gmail/Google Apps Email extension is working on Magento 1.3.2.4, I use that currently combination for one of the stores I run. You could try loging in and out of Magento? Also, please paste the URL that is giving you a 404 error?
Ashley,
I have logged out and back in of the admin and I still get the 404.
The URL I see in the browser address bar of the page on which I see the 404 is http://[host]/magento/index.php/admin/googleappsmailtest/index/index/
Kevin
That url looks like it’s missing a key, do your other admin urls have a key?
Nope, no keys on any admin URLs.
Your extension appears to work (thanks by the way). It’s just the self test that’s not working.
Kevin
Hmm, I think there is a security setting for using admin url keys, I wonder if the self test fails when not using those. If you have time to try it out, please let me know. Otherwise, glad to hear that the actual functionality is working, though I’d hope so – I’m using it in production! 🙂
I’ve enabled the admin URL keys and still get the 404. Here’s the URL on which I see the 404:
http://[host]/magento/index.php/admin/googleappsmailtest/index/index/key/feafaf25c26987c8c20d35d36cef5884/
Any ideas?
Thanks for following up with these, I have to say, it’s a bit of tricky one eh. Well I have a brand new version of both of my magento email extensions combined into one that I am hoping to release very soon, if you’d like to you could install a pre-release version and beta test it – but I have to warn you, I’m not using it in production yet, and I don’t think others should, it needs some more testing. It does have a self test though, so if you wanted to try a different extension, to see if that change anything, I could send you a copy, let me know? Cheers, Ashley
Hi!
I face this error when running self-test.
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 ———–:
Unable to send test email. Exception message was: 535-5.7.1 Username and Password not accepted. Learn more at …
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.
Hi, I’ll ask the obvious question first; is the username and password correct? You need to verify it by going to the web interface, here: mail.google.com/a/your_domain and login. If that all checks out, then let me know, it might be something weird with the passwords. Cheers, Ashley
I installed the module and had a successful test. However, none of the emails sent within Magento are being sent through Gmail. I am running Magento version 1.3.2.4.
Ashley,
Thanks for the offer to try the beta, but I think I’ll wait.
Kevin
Have you got any other Magento Email extensions installed by any chance? Please try the extension on a fresh install of Magento on the same server/environment – if it still fails let me know and I can help try to diagnose.
nothing ventured, nothing gained 🙂 Keep an eye out for the proper release shortly!
I had your gmail extension working find but suddenly it stopped working and I am getting the out port 587 is closed error. I have spoken to my host and they say port 587 is open. they have asked “Can you give me an address or IP that I can try and connect to on port 587 for Google so I can try and find out what is going on?” What should I tell them??? thanks heaps
Best thing to test for is connectivity direct to the gmail smtp servers at smtp.gmail.com – after all that is what the extension needs to connect to. Let me know how you get on.
Hi Ashley,
The Gmail apps extension is a great contribution to the community, one thing I noticed is when the plugin gets installed on a unix machine, some of the files don’t get copied into the right places. After installing via magento connect, files were put into /downloader/Z:/home/magento.com/www/app/(code|etc) and they probably should have gone into /app/(code|etc),
Since they weren’t copied over correctly, from the admin menu you didn’t seen any additional configurations but once they were copied correctly everything showed up as expected.
Hope that helps.
-Jeff
thank you thank you! works great. our contact form wasn’t able to send emails to our google apps domain… they just never came through. once i added your extension, our emails were coming through (I think google apps were blocking inbound messages to our domain that had our domain in the “from:” field but were did not use authenticated smtp). Thanks!
Hi, Jeff. That looks more like an issue with the Magento install than with the extension itself, have you tried installing any other extensions and got different results?
Hi Ashley,
Hey thanks for replying, because of your suggestion that is might be something with the Magento install I took a closer look. Lo and behold I found the pear.ini file was configured improperly due to the fact the Magento install was a copy from another developer… this could have caused headaches in the future.
Once pear was re-configured everything was golden.
Thanks for nudging me in the right direction,
Jeff
Hello thanks again for the gmail app. It was working great until recently when people stopped getting emails from my site. When I ran the test I now get the port 587 is closed message. I have spoken to my host and the assure me the port is open and they are able to contact imap.gmail.com through port 587 on my server. They also say no changes have been made on my server. I have also uninstalled and reinstalled the megento extention but it is still not working. Do you have any other ideas on what problem might be? Thanks in advance. Ross
Hi, Ross
You need to test connectivity to smtp.gmail.com (not imap) – though if you can get to one, you should be able to get to the other. Also you must test it on the actual server that the extension is running from. If both of those things have been done, and still no emails get sent, then perhaps some security setting in Apache/PHP on your host disallows PHP making outbound connections directly? The emails may still send regardless? Also, do try logging in to gmail/google apps from the web interface google provides, it might be requiring you to enter a captcha (though that error would not cause the connection problems).
Cheers,
Ashley
Hi Ashley,
I have a very ambitious feature request. Wouldn’t it be great if we could somehow using google’s api view google docs, google calender and our google apps mail all from the comfort of our magento admin panel?
That is very ambitious! Plus Google already offers such great web based tools for those services, maybe a better integration would be a mini Magento Dashboard widget for your Google home page – so you can see order status/sales from within your Gogle apps domain?
Hi — I installed this this weekend, and we did get some errors. Customers were getting an “there was an error processing your order” error. When we dug into the code, it appeared orders were going through, but the extension was throwing an error so customers were not getting a “success” message.
so i turned on logging, ran a transaction, and got this: “exception ‘Zend_Mail_Exception’ with message ‘Subject set twice’ in /home/{{MY MAGE}}/lib/Zend/Mail.php:615”
/home/{{MY MAGE}}/app/code/community/Aschroder/GoogleAppsEmail/Model/Email/Template.php(58): Zend_Mail->setSubject(‘=?utf-8?B?RGVza…’)
We changed the “Send Order Email Copy Method” from “separate email” to “BCC” and orders began going through again.
FYI.
this is what is throwing the exception (in the Zend framework)…
/**
* Sets the subject of the message
*
* @param string $subject
* @return Zend_Mail Provides fluent interface
* @throws Zend_Mail_Exception
*/
public function setSubject($subject)
{
if ($this->_subject === null) {
$subject = $this->_filterOther($subject);
$this->_subject = $this->_encodeHeader($subject);
$this->_storeHeader(‘Subject’, $this->_subject);
} else {
/**
* @see Zend_Mail_Exception
*/
require_once ‘Zend/Mail/Exception.php’;
throw new Zend_Mail_Exception(‘Subject set twice’);
}
return $this;
}
Hi Ashley,
Ive got a weird one, I hope you can help.
Im using your gmail simple smtp extension (0.5) and the Aheadworks extension product questions. When people send a email it goes into the magento system admin, and I can answer it from the admin. Once I get the question answered and hit send it goes back to the customers email address that they posted. But when they reply back to me it goes to ‘general’ or ‘general@yahoo.com’. I have the setting set to: Use Store Email Addresses for Reply-to [yes].
Please any help would be greatly appreciated.
–Thanks,
Bryan
Hi,
Sounds like a setting in the product questions extension that must be sending as the ‘general’ contact, either disable the reply-to setting, in which case emails will return to the address that sent them, or check the code of the extension to see if you can make it use a different contact?
Cheers,
Ashley
Ashley
Thanks for your help. I look in the product questions extension and found this line of code in their productquestionscontroller.php file:
->setReplyTo(Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER))
I removed that and it appears to be working. If it acts up again I will let you know. I posted it here thinking someone else might find this useful as well.
–Bryan Sammon
Thanks Bryan, I appreciate you reporting back on the solution.
I had a Google Base/Magento problem and your site here steered me to the fix. Glad I found you, and thanks. Cool pics, btw. I hope to see NZ one of these days. Best regards,
Fred
hi there
i run self test and email is delivered fine. i set Enable Google Apps Email to YES and emails are still sent from my server postfix not from google apps. I run this test on my fresh development Magento ver. 1.3.2.4. with cache disabled. Any idea what i might be doing wrong?
Not really – but try enabling logging in magento and then run the self test, send a contact form, sign up for the newsletter and create a new order and see what is logged – my extension is written so that it will log out debug if logging is enabled. Let me know what it outputs.
thanx, i dont know why but logging doesnt work on my magento instalations.. maybe something with php settings, anyhow i got extension to work (my fault of course dev magento wasnt as fresh as i thought and there was a small extension that sends invoices as pdf which was was conflicting)
now it works fine except when i send email from contact us form i get this error
Fatal error: Call to a member function getName() on a non-object in /magento/app/code/core/Mage/Core/Model/Resource/Setup.php on line 218
(this time its completely fresh install with nothing changed) – althoug contact-us email is delivered fine even with that error. Thanx
looks like variable from template that is causing error but it has nothing to do with your extension probably… dont worry about that error
Brilliant, thanks for the update. Glad to hear it’s all sorted now.
anybody fammiliar with 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 k.jahangier@gmail.com:
Unable to send test email. Exception message was: Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\xampp\htdocs\magento\lib\Zend\Mail\Protocol\Smtp.php on line 206…
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.
It means you don’t have openssl installs. On windows you just enable the openssl.dll in the php.ini configuration file. You may even be able to control it through the XAMP interface?
I`ve OpenSSL and enabled open ssl in the php.ini file and restarted the server.
http://img402.imageshack.us/img402/8739/openssl.jpg
I am having the same problem (“this stream does not support SSL”) but my server is a unix box. I am hosted with GentoHosting.com
I’ll have to give them a buzz. Any recommendations on what I should tell them? Is it as simple as enabling with php.ini?
Thanks
I have to be honest, I haven’t used a windows computer for about 8 years – I’m definitely not the best person to be talking to about this, but I can say the error you get with my extension is related to not having openssl.
if you have a web host, ask them to enable open ssl for php – they should be able to fix it, if not get a better magento host.
Ssl is installed and enabled in php.ini, see picture in my previous post.
I can confirm I have v0.5 running on 1.3.2.4.
I would suggest making a note, somewhere in the documentation or above the self test link, that you need to save the user/pass first before running the test. It took me forever being an idiot before I realized what I was doing wrong.
Hi,
Running your extension on my test/development server and it works a treat except for the Contact Us form. I get a ‘contact us unable to submit request’ error.
This seems to be a known problem in Magento but with no clear fix apart from hacking out the standard smtp code. Any thoughts?
Thanks – this is fixed in the upcoming new release. Stay tuned 🙂
Hi, are you sure there are no other conflicting extensions?
Hi Ashley
Not sure if your two previous comments were aimed at me.
I don’t have any other extensions.
Are you saying next release will fix the ‘contact us’ form
Hi, Jem – sorry crossed lines – the next release makes it clear you need to save the connection details before running the smtp/gmail self test.
In terms of the Magento contact form not working – I’d suggest you enable logging and then run through it and send me the logging to see if my extension is even being called and what point it is getting up to in the send process.
Cheers,
Ashley
Hi Ashley,
I set the google App email in SMTP Pro and Google Apps Emails setting extension.
1. SMTP Pro extension is not working.
2. Regarding to Google Apps Emails setting, the auto responder is not working and sender is set to hosting email address, not Google App email.
Would you let me know how auto responder works?
Best Regards,
James
Anyone encountered this before?
My website is not sending out any e-mail.
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 timed out(110)
This extension requires an outbound SMTP connection on port: 587
Sending test email to your contact form address info@discerningbooks.com:
Unable to send test email. Exception message was: Connection timed out…
Please check and double check your username and password.
Testing failed, please review the reported problems and if you need further help visit ASchroder.com to contact me.
FYI: The problem is not due to Ashley’s extension. It existed even before I installed Ashley’s extension.
Thanks for the time reading this post.