Thursday, January 22, 2009

Using Gmail for Internal Email

by Greg Pike, Applecore Web Developer

A Little Background
At our office we use one email for sending all of our server-generated emails. We have scripts that connect to the server and use that email for sending notifications, contact forms, and other website-related emails. In the past our scripts could send emails and mask who they were coming from by simply changing the value of the "From" field. For instance, if I went to a contact form and entered my email as
johnsmith@example.com and click Send, the email received should appear from johnsmith@example.com rather than the generic email used by the server for sending mail.

For years, with our host, this was never a problem. We recently switched our email host to Gmail and, along with a few other technical hiccups from the switch, we had a problem with masking emails as from a specific sender.

Why is there even a problem sending these emails from Gmail?
Gmail blocks server-generated emails from masking who they’re from. Gmail forces the developer to authenticate themselves as whatever email they want to send from. That is, if you wanted your script to send an email as John Smith you would need his username and password to send it from the server. This isn’t usually ideal, but Gmail is trying to prevent servers from sending emails from someone without their consent.

Disclaimer
We managed to come up with an ad-hoc solution to the problem for any small organizations, like ours, that run intranets or scripts that send external emails from employees or members. It isn’t glamorous and it unfortunately doesn’t really work for anyone who isn’t a part of your network, but it’s a solution that met our needs. And since we couldn’t find any references to it online, we’re making our own contribution.

Our solution
Log into the Gmail account you intend to send emails from. This account should be the one your web scripts access. Click Settings and go to Accounts. Here, add the account of each member of your network. You can do this by clicking "Add another email address." As long as John Smith is associated with the server email (the one you logged in to), Gmail can send emails as if they’re from his account. This goes for all members of the network.

It might be wise to explain to your organization ahead of time that you need them to confirm their association with this Gmail account. When you add them as an additional account they’ll receive an email that tells them they need to verify that they wish for their account to be associated with your server account.

Good luck with it!