The Quick Email Button
Jul 16, 2008…or, mastering the black art of URL hacking the email page.
Sending an email from Salesforce.com can be a clicky operation. You dig around for the Send An Email button, click it, click Select Template, find your template and click it, maybe type some more stuff in the email, and finally click Send. That's a lot of clicks, especially for organizations where they just use the same template over and over.
Well, the good news is that you can make this a much less clicky operation by making a custom button which changes the URL parameters. Technically URL-hacking is not supported by Salesforce.com, and it's technically not a supported API, so be forewarned -- but when you're on a quest to reduce clicks, you gotta do what you gotta do.
So let's say you have a template that you usually use for Cases which contains some pleasantries and then a merge field that adds in the text of any related Solutions. If you've not used Email Templates much before, by the way, have a look at the sample template entitled "SUPPORT: Case Response with Solution (SAMPLE)" -- it does just what I've described here.
Anyway, what you'll want to do is make a custom button that preselects this template. It's quite simple really.
The first thing you'll need to do is get the ID of the template you want to use. This can be found by finding the template via Setup->Communication Templates->Email Templates. Click on it and look in the URL -- you'll see an ID up there that looks like 00X30000000rNM0 (which may be followed by a ? with some other parameters -- ignore that stuff, just take the 15-character ID that starts with 00X). Copy that ID into Notepad or someplace where you can get to it later.
Now go to Case and create a Custom Button -- let's call it Email Solution. Set its Behavior to Execute Javascript and its Display Type to Detail Page Button.
In the Javascript area add this line of code, replacing the <your template here> with the ID of the template you saved earlier:
location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>');
Now add this custom button to your Case page layout, and voila, you have a one-click button that will bring up your email complete with template.
But wait, there's more!
To this we can actually add a few more bells and whistles.
By default the Send An Email page likes to BCC the sender. Many call center agents I talk to find this rather annoying. With the addition of another URL parameter to our custom button, we can stop it from BCCing anyone. The parameter is p5, so our new code would be:
location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>&p5=');
Notice at the end there the "&p5=" -- that sets the BCC area to empty.
But what if you just want to send the email in one click with no edits?
Well, you can do that too, with -- you guessed it -- one more URL parameter: the save parameter.
If I take the above code and add a save=1 to it, then when I click the button, the email will just be sent, and the Case page will refresh itself to indicate that an email was sent:
location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>&p5=&save=1');
And what if you want to change the From address?
You may have noticed that if you have Email To Case enabled with some routing addresses, or if you've modified the email address in the My Email Settings page in the Personal Information area of Setup, that when you go to send an email you have a choice of From addresses. You can default this From address too!
The From address is just another parameter in the URL -- it's p26. So taking our earlier example, let's add a From address default:
location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>&p26=me@mydomain.com');
Note that the p26 default will only work for items that are actually in that From address list.
And that ends today's lesson on email buttons. Happy emailing!

I've just reworked the javascript provided to add a similar button to my Lead record, including the bcc removal -
location.replace('/_ui/core/email/author/EmailAuthor?p2_lkid={!Lead.Id}&rtype=00Q&retURL={!Lead.Id}&template_id=&p5=')
I have an enquiry form set up on my website, and send the same email template to new leads. This saves me looking up and selecting the email template each time so is very usefui
thanks!
Posted by: Andrew | March 22, 2009 at 02:13 AM
How would I go to CC'ing all members of the account team? Is there a merge field available or a custom parameter for emailauthor.jsp?
TIA!
Posted by: DenisK | May 05, 2009 at 11:35 AM
This whole bit of functionality is cool and Salesforce should be talking it up a lot more since it's a major advantage of properly constructed web-based services.
But where pray tell is more complete documentation??
Posted by: pbreit | May 22, 2009 at 09:27 AM
Thank You! I need to create a quick custom button that directed to a specific template today and this worked perfectly!
Posted by: Tami | May 22, 2009 at 03:48 PM
Is this the part where I define the recipeint of the email
of&p2_lkid={!Case.ContactId}
Posted by: Stephen | June 01, 2009 at 11:42 AM
If anyone is having trouble using this and their solution attachments not being transferred to the e-mail then you need to add the following to the url:
&new_template=1
Posted by: Yori | June 12, 2009 at 11:32 AM
Is is possible to utilize this script on custom objects?
Posted by: ReubenB | June 15, 2009 at 02:38 PM
Please direct all questions to the General Development board:
http://community.salesforce.com/sforce/board?board.id=general_development
Posted by: Marco Casalaina | June 16, 2009 at 10:22 AM
Amazing! We will create a quick button with a default template to all users in our org. Juan Manuel Garrido. EGA Futura.
Posted by: EGA Futura Software | July 20, 2009 at 09:48 AM
Now how to customize the "send email" button to do a REPLY _WITH_ a predefined template?
It looks like the variables "template_id" and "reply(toall)" conflict with one another.
Posted by: Pierre Eymard | September 22, 2009 at 11:16 AM