+ Start a Discussion
EJEJ 

Sending template e-mails in an scontrol.

I realize this is unsupported currently, but is there any way to create a new template e-mail and have it send immediately from an scontrol? I'm already creating the new e-mail, but currently it just opens into a standard send e-mail window and I can't find any URL parameter to just have it send the e-mail without requiring a second click.

What I'm currently doing:

window.location.href = "/email/author/emailauthor.jsp?retURL=%2F{!Contact_ID}&rtype=003" + "&p2_lkid={!Contact_ID}&new_template=1&nosave=0&template_id=";

I could of course handle this outside an scontrol with an external web server and a custom link, but I'd prefer to handle everything within an scontrol to keep it contained within SFDC.

Is there any way to do what I want (supported or not) or am I stuck with manual intervention or an external solution?

BTW, adding &save=1 to that URL causes an internal server error, not sure if save=1 is supposed to work and is just currently broken or is just an unexpected URL parameter for this page that causes an error.

Thanks,
E.J.
Ron HessRon Hess
not supported disclaimer insert here...

i recently had occasion to work thru this problem,
only just got it to work and got pulled away.

this is in an scontrol,
// so put this function in the body onoad="initPage()"

function initPage() {
var form = document.getElementById('editPage');
form.elements['p6'].value = 'test'; // subject
form.elements['new_template'].value = 1;
form.elements['template_id'].value = '00X30000000buz7';// template id
form.method = "GET";
//setTimeout("window.close();",3000); // try this in a popup, otherwise reload()?
form.submit();
}

// then in the HTML body of the scontrol, you paste in the actual
// HTML src from the email author form page, cleaned up to suit your taste
// ---> drop editForm here
So, now your user clicks once, launches the scontrol, browser renders
the HTML form, then calls the init page, which finds the form,
loads a template id, perhaps fills some other data like a subject
then, calls submit(), which simulates the click on the send button.

to make this worthy it will have to close the frame properly and jumpback to
the opener, or close a popup, i didn't get that far.

sounds easier than it was to get all the correct values filled in, missing
values in the form will cause the crash you reported.
EJEJ
Worked like a charm, thanks.
BorthiryMBorthiryM
Hi:

I`m trying to make a scontrol to send a email using a template. I did the last but it didnt work. Can you explain again?
EJEJ

Here's the SControl I built for this.  If it doesn't come out right feel free to e-mail me at "ej_wilburn AT kofax dot com".


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <title></title> <link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet" media="handheld,print,projection,screen,tty,tv" > <link href="/dCSS/Theme2/default/custom.css" type="text/css" rel="stylesheet" media="handheld,print,projection,screen,tty,tv" > <script type="text/javascript" src="/js/functions.js"></script> <script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>

<script language="javascript"> <!--

function refresh() { opener.location.href = opener.location.href }

function jumpBack() {  top.location.href = "/{!Contact_ID}"; }

function closeWindow() {  refresh(); // window.parent = window;  window.close(); }

// Initialize our SalesForce.com connection function pageInit() {  // Reuse our current session.  sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");    // We don't have a valid session, error out.  if ( sforceClient.getSessionId().indexOf("API_Session_ID") != -1 )  {   alert("Error: Could not login to Enterprise Edition API \nthis control only runs on Salesforce.com Enterprise Edition");   closeWindow();   return;  }    // Send out the invitation e-mail.  sendInvitation();     closeWindow(); }

// Send the invitation. function sendInvitation() {  var form = document.getElementById('editPage');

 // Setup the e-mail form for submission.   // Set a CC address.  form.elements['p4'].value = "cc_address@none.com";  // BCC the current user.  if ( "{!User_Email}".length > 0 )   form.elements['p5'].value = "{!User_Email}";  // We're forced to use a subject, it will be overidden by the template when we submit.  form.elements['p6'].value = 'None Yet'; // subject  // Let the e-mail page know we're using a template.  form.elements['new_template'].value = 1;  // Specify which template is being used.  form.elements['template_id'].value = '00X30000000ljL3';  form.method = "GET";    // Mark the contact as invited if it's not already set to "Sent".  if ( "{!Contact_PartnerNet_Invite_Status}" != "Sent" )   updateContactInviteStatus();    // Submit the form and send the e-mail.  form.submit(); }

// Mark the contact as invited. function updateContactInviteStatus() {  // Update the contact.  var contact = new Sforce.Dynabean("Contact");  contact.set("Id", "{!Contact_ID}");  contact.set("PartnerNet_Invite_Status__c", "Sent");  var saveResult = sforceClient.update([contact]);    // Check for errors.  if ( saveResult.className.toLowerCase() == "array" )  {   if ( saveResult[0].success == false )   {    alert( "Error!  Unable to update the Contact's PartnerNet invite status, please contact support.\n\rError Details: " +     saveResult[0].errors[0].message );    jumBack();    return;   }  }  else  {    alert("Error!  Unable to update the Contact's PartnerNet invite status, please contact support.\n\rError Details: " +     saveResult.detail.fault.exceptionMessage);    jumBack();    return;  } }

--> </script></head> <body onload="pageInit()" class="customTab22 overviewPage" > <BR> <BR> <P align=center>Sending invitation...</P> <DIV style="Visibility: hidden;"> <form  action="/email/author/emailauthor.jsp" id="editPage" name="editPage" method="POST" ><input type="hidden" name="cancelURL" id="cancelURL" value="/{!Contact_ID}"><input type="hidden" name="docancel" id="docancel" value="0"><input type="hidden" name="id" id="id0" value="00Y30000002a1Zg"><input type="hidden" name="id" id="id1" value="00Y30000002a1Zg"><input type="hidden" name="new_template" id="new_template" value=""><input type="hidden" name="nosave" id="nosave" value="0"><input type="hidden" name="retURL" id="retURL" value="/{!Contact_ID}"><input type="hidden" name="save_new_url" id="save_new_url" value="/email/author/emailauthor.jsp?retURL=%2F" + "{!Contact_ID}" + "&amp;rtype=003&amp;p2_lkid="{!Contact_ID}"><input type="hidden" name="template_id" id="template_id" value=""><input type="hidden"  id="rtype" name="rtype" value="003"> <div class="pbBody"><div class="pbSubheader first tertiaryPalette" id="head_1_ep"><span class="pbSubExtra"><span class="requiredLegend"><span class="requiredExampleOuter"><span class="requiredExample">&nbsp;</span></span><span  class="requiredText"> = Required Information</span></span></span><h3>Edit Email<span  class="titleSeparatingColon">:</span></h3></div><div class="pbSubsection"><TABLE  class="detailList" cellpadding="0" cellspacing="0" border="0"><TR><TD class="labelCol">Email Format</TD><TD class="data2Col" colspan="3">&nbsp;<b>Text-Only</b>&nbsp;&nbsp;[&nbsp;<a href="javascript:switchTextMode()"><b>Switch to HTML</b></a>&nbsp;]</TD></TR> <TR><TD class="labelCol"><label for="p2">To</label></TD><TD class="data2Col" colspan="3"><input type="hidden" name="p2_lkid" id="p2_lkid" value="{!Contact_ID}"><input type="hidden" name="p2_lkold" id="p2_lkold" value="Test Wilburn"><input type="hidden" name="p2_lktp" id="p2_lktp" value="003"><input type="hidden" name="p2_lspf" id="p2_lspf" value="0"><input type="hidden" name="p2_mod" id="p2_mod" value="0"><span class="lookupInput"><input  value="Test Wilburn" maxlength="80" type="text" onchange="document.getElementById('p2_lkid').value='';document.getElementById('p2_mod').value='1';" id="p2" size="20" name="p2"><a href="JavaScript: openLookup('/_ui/common/data/LookupPage?lknm=p2&lkfm=editPage&lktp=' + document.getElementById('p2_lktp').value,670,document.getElementById('p2_mod').value,'&lksrch=' + escapeUTF(document.getElementById('p2').value),'maxw')" title="To Lookup (New Window)" onclick="setLastMousePosition(event)" id="p2_lkwgt"><img src="/s.gif" alt="To Lookup (New Window)"  class="lookupPopup"></a></span></TD></TR> <TR><TD class="labelCol"> <select  title="Object Type" onchange="document.getElementById('p3_lktp').value=document.getElementById('p3_mlktp').options[document.getElementById('p3_mlktp').selectedIndex].value;document.getElementById('p3_lkid').value='';document.getElementById('p3_mod').value='1';" id="p3_mlktp" name="p3_mlktp"> <option value="001" selected>Account</option></select></TD> <TD class="data2Col" colspan="3"><input type="hidden" name="p3_lkid" id="p3_lkid" value="000000000000000"><input type="hidden" name="p3_lkold" id="p3_lkold" value="null"><input type="hidden" name="p3_lktp" id="p3_lktp" value="001"><input type="hidden" name="p3_lspf" id="p3_lspf" value="0"><input type="hidden" name="p3_mod" id="p3_mod" value="0"><span class="lookupInput"><input  maxlength="80" type="text" title="Case" onchange="document.getElementById('p3_lkid').value='';document.getElementById('p3_mod').value='1';" id="p3" size="20" name="p3"><a href="JavaScript: openLookup('/_ui/common/data/LookupPage?lknm=p3&lkfm=editPage&lkrf=&lktp=' + document.getElementById('p3_lktp').value,670,document.getElementById('p3_mod').value,'&lksrch=' + escapeUTF(document.getElementById('p3').value),'maxw')" title="Case Lookup (New Window)" onclick="setLastMousePosition(event)" id="p3_lkwgt"><img src="/s.gif" alt="Case Lookup (New Window)"  class="lookupPopup"></a></span></TD></TR> <TR><TD class="labelCol"><label for="p24">Additional To</label></TD><TD class="data2Col" colspan="3"><textarea  cols="65" rows="2" maxlength="2000" type="text" wrap="soft" id="p24" name="p24"></textarea></TD></TR> <TR><TD class="labelCol"><a href="javascript: openPopup('/email/author/emailccbcclookup.jsp?wid={!Contact_ID}', 'CCBCCLookup', 420, 390, 'width=420,height=390,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no', true);" title="CC (New Window)" onclick="javascript: setLastMousePosition(event);">CC:</a></TD><TD class="data2Col" colspan="3"><textarea  cols="65" rows="2" maxlength="2000" type="text" title="CC" wrap="soft" id="p4" name="p4"></textarea></TD></TR> <TR><TD class="labelCol"><a href="javascript: openPopup('/email/author/emailccbcclookup.jsp?wid={!Contact_ID}', 'CCBCCLookup', 420, 390, 'width=420,height=390,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no', true);" title="BCC (New Window)" onclick="javascript: setLastMousePosition(event);">BCC:</a></TD><TD class="data2Col" colspan="3"><textarea  cols="65" rows="2" maxlength="2000" type="text" title="BCC" wrap="soft" id="p5" name="p5"></textarea></TD></TR> <TR><TD class="labelCol requiredInput"><label for="p6"><span class="requiredMark">*</span>Subject</label></TD><TD class="data2Col" colspan="3"><div class="requiredInput"><div class="requiredBlock"></div><input  maxlength="100" type="text" id="p6" size="70" name="p6"></div></TD></TR> <TR><TD class="labelCol last"><label for="p7">Body</label></TD><TD class="data2Col last" colspan="3"><textarea  cols="93" rows="15" maxlength="32000" type="text" wrap="soft" id="p7" name="p7"></textarea></TD></TR> </TABLE></div></div> <div class="pbFooter secondaryPalette"><div class="bg"></div></div></div> <input type="hidden" name="textmode" value="t"> <input type="hidden" name="save" value="1"> <input type="hidden" name="deleter" value=""> <input type="hidden" name="deleter_type" value=""> </form> </DIV> </body></html>


Message Edited by EJ on 02-21-2006 10:54 AM

BorthiryMBorthiryM
thanx, i`ll try it

;)
Mike @ PartnersMike @ Partners
Dont know if you got this working or not. But it sound like this would do the trick for you.

All you really need is a custom link that looks like this:

Code:
https://na1.salesforce.com/email/author/emailauthor.jsp—retURL=/{!Object_ID}&p3_lkid={!Object_ID}&template_id=00X30000000uI6O&save=1

 
The 'save=1' at the end will auto send the e-mail

hope this helps
cpierrecpierre

Very helpful !!

Currently I have an e-mail template (Alert) that is kicked off based on a rule.  I'd like the ability for users to simply click a yes or no link in the email -

on click - it  would fwd that email with their response to one receiver

How can this be done?:smileyindifferent:

BerndWBerndW
Hi,

that works fine. But one additional question:
Is it possible, to attach a document to such a mail? I already have tried with:
attach=1&file=AttachmentId

And it worked. But only, if I have send such a mail over the interface before I have tried to send it with a link and only for some hours.
It seems, that the attachmentId (starting with 00Y...) is generated dynamically, when sending a single mail to a Contact and will be deleted some hours later?

Does anybody has a idea, how to add a attachment using a other ID which is fix?

Thanks
FinTechFinTech
Is it possible to update a checkbox on the calling page? I have situation where I need to update a checkbox from an email send form.
Mike @ PartnersMike @ Partners
Some one was asking about this, here is a good explanation.
///

Here is the link:
https://na1.salesforce.com/email/author/emailauthor.jsp?p2_lkid=******&retURL=/******&p3_lkid= ******&template_id=******&save=1
This is how it works:
Where every there is the '*****' you need to replace it with the id of the record.

[p2_lkid=] is where you would put the contact or lead id you want to recive the e-mail
ex: 'p2_lkid= 0036000000cmB8N'

[retURL=/] is where you put the id of the object you would like them to goto after the e-mail has sent
ex: 'retURL=/0036000000cmB8N'

[p3_lkid=] is where you put the id of the record you want the e-mail associated with, like with an opportunity, or account.
ex: 'p3_lkid=00130000006VfYf'

[template_id=] is the template id you wont the e-mail to use.
ex: 'template_id=00X30000000uI6O'

[save=1] is what makes the e-mail auto send.
if you dont want the e-mail to auto send just leave this off.

To get the id of any record including email templets, navigate to the record and in the url bar you should see 'https://na4.salesforce.com/' and then a combination of letter and numbers. This is the id of that record.

A final link would look like this:
ex: 'https://na1.salesforce.com/email/author/emailauthor.jsp?p2_lkid= 0036000000cmB8N&retURL=/0036000000cmB8N&p3_lkid=00130000006VfYf&template_id= 00X30000000uI6O&save=1'

if you were to make a url link on a contact page layout, it might look like this:
ex: 'https://na1.salesforce.com/email/author/emailauthor.jsp?p2_lkid= {!Contact.Id}&retURL=/{!Contact.Id}&p3_lkid={!Contact.Public_WorkshopId__c}&template_id= 00X30000000uI6O&save=1'


Let me know if this help. hope it does.
Mike