+ Start a Discussion
sabelstromsabelstrom 

POST to emailauthor.jsp from outside SFDC

If I have a binding from an external application, is there a way to post to the emailauthor.jsp servlet? Can I pass url and sessionid (and anything else?) as additional form fields in a POST request?

I've been able to replicate the form in an s-control, set its values, and submit it, but to be able to run as a process not requiring s-control to be loaded in a client browser (i.e. - run in a server-side function) would be ideal. i'm aware that i could get to the page via the frontdoor.jsp route, but even then, i'm programmatically "navigating" thru SFDC, rather than more efficiently just accessing the relevent servlet.

If this cannot be done due to design or security decision - it would be a great enhancement. Since email templates are not accessible via API, sending emails from external smtp is not ideal from content/template administrative perspective.

Any help would be greatly appreciated!!
Ron HessRon Hess
it's possible to post to emailauthor but it's not supported, so be aware that it may change at any time.
basicaly you need to create a user agent, as you say at the front door, get back a session such that the user agent is auth (sid is in a cookie i think), then you can post to emailauthor, it's sort of frowned upon, clumsy and slow, nothing to be proud of, but, hey sometimes success comes in strange ways.

Message Edited by Ron Hess on 11-18-2005 07:17 PM

Venkat PolisettVenkat Polisett
Ron,

We are looking for sending few emails from a Java application to Salesforce Website. Can you please give some psuedo code about the things that you are talking about below.

Here is what I understood and coded but it is not send the email to the contact in salesforce:

Code:
    public static void main(String[] args)
    {
     try
     {
   String userName = URLEncoder.encode("xyz@xyz.com", "UTF-8");
   String pw = URLEncoder.encode("adafda", "UTF-8");
   
   URL url = new URL("http://www.salesforce.com/login.jsp");
   URLConnection connection = url.openConnection();
   connection.setDoOutput(true);
 
   OutputStreamWriter out = new OutputStreamWriter(
                               connection.getOutputStream());
   out.write("username=" + userName);
   out.write("&pw=" + pw);
   out.close();
   
        BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
          System.out.println("Login out = " + line + "\n");
        }
        rd.close();
   
        String emailUrl ="https://na4.salesforce.com/email/author/emailauthor.jsp";
         
        String data = URLEncoder.encode("retURL", "UTF-8") + "=" + URLEncoder.encode("/a0C60000000Fwk4", "UTF-8") +
             "&"+ URLEncoder.encode("template_id", "UTF-8") + URLEncoder.encode("00X30000000qosR", "UTF-8") +
             "&"+ URLEncoder.encode("new_template", "UTF-8") + URLEncoder.encode("1", "UTF-8") +
             "&"+ URLEncoder.encode("p2_lkid", "UTF-8") + URLEncoder.encode("0036000000KjEFL", "UTF-8") +
             "&"+ URLEncoder.encode("p3_lkid", "UTF-8") + URLEncoder.encode("a0C60000000Fwk4", "UTF-8") +
             "&"+ URLEncoder.encode("save", "UTF-8") + URLEncoder.encode("1", "UTF-8");
   
        URL email = new URL(emailUrl);
 
        URLConnection emailConnection = email.openConnection();
        emailConnection.setDoOutput(true);
        
 OutputStreamWriter emailOut = new OutputStreamWriter(emailConnection.getOutputStream());
 emailOut.write(data);
 emailOut.close();

        rd = new BufferedReader(new InputStreamReader(emailConnection.getInputStream()));
         
        while ((line = rd.readLine()) != null) {
          System.out.println("Email out = " + line + "\n");
        }
        rd.close();   
     }
     catch (Exception e)
     {
      System.out.println(e.toString());
     }
    }
It is producting the following output:

Login out = The URL has moved <a href="https://na4.salesforce.com/secur/frontdoor.jsp?sid=w1ZxLSK0toYy3vKVnKsV.WbAdMnzofpaeAGeXsqilDXhR_GP5nkTvo8K5GrrcE9nJtZbagI9RR0Vfv.MyaIYmqRrGBDHjP369lzUiIAv3qZRvr1AAJI%3D&je=0&cshc=0000000tc5n00000001VjI">here</a>

Email out = <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Email out = <html>
Email out = <head>
Email out =     <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
Email out = <script>
Email out = if (window.location.replace){
Email out = window.location.replace('https://www.salesforce.com/login.jsp?ec=302&startURL=%2Femail%2Fauthor%2Femailauthor.jsp');
Email out = } else {;
Email out = window.location.href ='https://www.salesforce.com/login.jsp?ec=302&startURL=%2Femail%2Fauthor%2Femailauthor.jsp';
Email out = }
Email out = </script>
Email out = </head>
Email out = </html>
Email out =
Email out = <!--
Email out = -->

Any help would be appreciated.


Ron Hess wrote:
it's possible to post to emailauthor but it's not supported, so be aware that it may change at any time.
basicaly you need to create a user agent, as you say at the front door, get back a session such that the user agent is auth (sid is in a cookie i think), then you can post to emailauthor, it's sort of frowned upon, clumsy and slow, nothing to be proud of, but, hey sometimes success comes in strange ways.

Message Edited by Ron Hess on 11-18-2005 07:17 PM