Posted on

Google Apps Email/Gmail Magento Extension v0.5 released

It’s been a while since I have written any updates on my Gmail and Google Apps email extension for Magento. I have just released version 0.5 and thought now would be a good opportunity to write a quick update on the changes and what I have planned for SMTP email support in Magento.

Version 0.5 of Google Apps Email/Gmail Magento Extension

Firstly the changes in the latest release of the Google Apps/Gmail Magento extension. Both have been inspired by user feedback so two ‘thank you’s to follow. Firstly thanks to Blue Acorn for pointing out the lack of multi-store capability on the self test. It’s actually a little clunky getting the store parameters in the admin of Magento, my custom button needed to add the parameter like so:

$buttonBlock = $this->getElement()->getForm()->getParent()->getLayout()->createBlock('adminhtml/widget_button');
 
$params = array(
    'website' => $buttonBlock->getRequest()->getParam('website')
);
 
$url = Mage::helper('adminhtml')->getUrl("googleappsmailtest", $params);

And then the controller needed to actually pick up which Magento store to get the config for:

$websiteModel = Mage::app()->getWebsite($this->getRequest()->getParam('website'));
 
$to = Mage::getStoreConfig('contacts/email/recipient_email', $websiteModel->getId());

The other change was a bit of a curve ball. I had a Magento + Gmail user named Matt contacted me with what seemed to be an unrelated issue. I have been poking around in the installation code trying to figure out what has been happening. It wasn’t until I did a full fresh install on Magento 1.3.2.3 that I noticed what was going on. My extension has a dependency on Mage_Core (obviously, right?) and the wiki guide on how to package Magento extensions says to include this dependency. However if you do then the downloader will download the Core files and a whole bunch of other required files. This is no problem if you have been a good boy or girl and made your changes to the themes outside of the default files, but if you have changed the default templates then there is a risk of your changes being lost!

So, the change is to remove this dependency, even though the guide says it should be there. It’s kind of obvious that you need Magento in order to run my extension anyway!

Magento SMTP support

The other update I wanted to post was that I am working on porting my Magento Gmail / Google Apps extension to also support full SMTP capability. I will be releasing the changes as a new extension, as it is important to me that the original goal of this extension (extreme simplicity and ease of use) is not lost under the weight of full SMTP configuration.

I know that there is already an older SMTP extension for Magento. I think I can improve upon it in several ways, I have developed Magento SMTP self test capability, and I have support for Magento newsletter sending. The current SMTP extension hasn’t been updated for nearly a year, and I have an opportunity to create a more modern, user friendly extension.

I’ll be working on it over the next few days and would invite feedback from anyone with ideas on ways to improve the Magento SMTP functionality.

Posted on

Using Gmail or Google Apps email with Magento

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.