+ Reply to Thread
Results 1 to 9 of 9

Thread: sendMail()

  1. #1

    sendMail()

    Hi Mike,

    using the PHP snippit forsending an email with the v13 of the phpToolkit is rendering me this error:

    ***** Send Emails ***** Function ("sendEmail") is not a valid method for this service

    My PHP looks like this:

    PHP Code:
    <?php

    error_reporting
    (E_ALL & ~ E_NOTICE);

    $SOAPCLIENT_DIR="soapclient/";

    ini_set("soap.wsdl_cache_enabled""0");
    require_once (
    "$SOAPCLIENT_DIR/SforcePartnerClient.php");
    require_once (
    "$SOAPCLIENT_DIR/SforceHeaderOptions.php");

    require_once (
    'SalesforceUserSettings.php');

    $partner_wsdl "partner.wsdl.xml";

    try {
      
    $mySforceConnection = new SforcePartnerClient();
      
    $mySoapClient $mySforceConnection->createConnection('partner.wsdl.xml');
      
    $mylogin $mySforceConnection->login($USERNAME$PASSWORD);

      
    $singleEmail1 = new SingleEmailMessage();
      
    $singleEmail1->toAddresses 'ron@byressecurity.com';
      
    $singleEmail1->plainTextBody "Hello there";
      
    $singleEmail1->subject "First Single Email";
      
    $singleEmail1->saveAsActivity true;
      
    $singleEmail1->emailPriority EMAIL_PRIORITY_LOW;

      
    $singleEmail2 = new SingleEmailMessage();
      
    $singleEmail2->toAddresses 'ron@byressecurity.com';
      
    $singleEmail2->plainTextBody "Hello there";
      
    $singleEmail2->subject "Second Single Email";
      
    $singleEmail2->saveAsActivity true;
      
    $singleEmail2->emailPriority EMAIL_PRIORITY_LOW;

      echo 
    "***** Send Emails *****\n";
      
    $emailResponse $mySforceConnection->sendSingleEmail(array ($singleEmail1$singleEmail2));

      
    print_r($emailResponse);

    } catch (
    Exception $e) {
      echo 
    $mySforceConnection->getLastRequest();
      echo 
    $e->faultstring;
    }

    ?>
    ....

    Thanks

  2. #2
    I'll add this bit, its in my Apache logs... fat chance finding this similar error on the inter web.

    PHP Fatal error: Call to undefined method SforcePartnerClient::sendEmail() in /var/www/html/sforce-ssp/sendEmail.php on line 34
    Easy to explain.. its not there, but why.. this is almost a direct copy of the snippit in the samples... SF make a change and not supporting this no more?

  3. #3
    Join Date
    May 2007
    Posts
    506
    Blog Entries
    3
    Hey i have not used this function yet in php and the new toolkit, if you give me a day or so, I can look into it and maybe I can help you out!

    Sorry

    ~Mike

  4. #4
    Thanks Mike!!

    nice skin on the forum. Looks good

  5. #5
    No idea what changed, but it seems to be working properly now... No permission changes, no firewall changes... caching issue perhaps.

    Anyways the enterprise and partner snippits are as follows:

    Partner snippit:


    PHP Code:
    <?php
    error_reporting
    (E_ALL & ~ E_NOTICE);

    $SOAPCLIENT_DIR="soapclient/";

    ini_set("soap.wsdl_cache_enabled""0");
    require_once (
    "$SOAPCLIENT_DIR/SforcePartnerClient.php");
    require_once (
    "$SOAPCLIENT_DIR/SforceHeaderOptions.php");

    require_once (
    'SalesforceUserSettings.php');

    $partner_wsdl "partner.wsdl.xml";

    try {
      
    $mySforceConnection = new SforcePartnerClient();
      
    $mySoapClient $mySforceConnection->createConnection('partner.wsdl.xml');
      
    $mylogin $mySforceConnection->login($USERNAME$PASSWORD);

      
    $singleEmail1 = new SingleEmailMessage();
      
    $singleEmail1->toAddresses 'brashr@itas.ca';
      
    $singleEmail1->plainTextBody "Hello there";
      
    $singleEmail1->subject "First Single Email";
      
    $singleEmail1->saveAsActivity true;
      
    $singleEmail1->emailPriority EMAIL_PRIORITY_LOW;

      echo 
    "***** Send Emails *****\n";
      
    $emailResponse $mySforceConnection->sendSingleEmail(array($singleEmail1));

      
    print_r($emailResponse);

    } catch (
    Exception $e) {
      echo 
    $mySforceConnection->getLastRequest();
      echo 
    $e->faultstring;
    }

    ?>

    Enterprise Snippit:


    PHP Code:
    <?php
    require_once ('SalesforceUserSettings.php');

    define("SOAP_CLIENT_BASEDIR""soapclient");
    require_once (
    SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
    try {
      
    $mySforceConnection = new SforceEnterpriseClient();
      
    $mySoapClient $mySforceConnection->createConnection('enterprise.wsdl.xml');
      
    $mylogin $mySforceConnection->login($USERNAME$PASSWORD);

      
    $singleEmail1 = new SingleEmailMessage();
      
    $singleEmail1->setToAddresses(array('brashr@itas.ca'));
      
    $singleEmail1->setPlainTextBody('My message');
      
    $singleEmail1->setSubject("A Single Email");
      
    $singleEmail1->setSaveAsActivity(true);
      
    $singleEmail1->setEmailPriority(EMAIL_PRIORITY_LOW);

      echo 
    "***** Send Emails *****\n";
      
    $emailResponse $mySforceConnection->sendSingleEmail(array($singleEmail1));

      
    print_r($emailResponse);
    } catch (
    Exception $e) {
      echo 
    $mySforceConnection->getLastRequest();
      echo 
    $e->faultstring;
    }
    Now I'll try and see if I can get attachments to work for this and get these email activities to use templates and be correlated with a case.

  6. #6
    Join Date
    May 2007
    Posts
    506
    Blog Entries
    3
    okay cool man, sometimes salesforce just has flatulence glad that you got it sorted out and thanks for posting an example, that really helps others here and me!!

  7. #7
    Here is the code to attach a text file to an email using the partner API.

    PHP Code:
    <?php
    error_reporting
    (E_ALL & ~ E_NOTICE);

    $SOAPCLIENT_DIR="soapclient/";

    ini_set("soap.wsdl_cache_enabled""0");
    require_once (
    "$SOAPCLIENT_DIR/SforcePartnerClient.php");
    require_once (
    "$SOAPCLIENT_DIR/SforceHeaderOptions.php");

    require_once (
    'SalesforceUserSettings.php');

    $partner_wsdl "partner.wsdl.xml";

    try {
      
    $mySforceConnection = new SforcePartnerClient();
      
    $mySoapClient $mySforceConnection->createConnection('partner.wsdl.xml');
      
    $mylogin $mySforceConnection->login($USERNAME$PASSWORD);

      
    //$caseID is the case ID I want this email to be associated with.
      
    $caseID '50080000006hFkW';
      
    //$contactID is the contacts ID I want this email to be sent to.
      
    $contactID '0038000000aILfh';

      
    $singleEmail1 = new SingleEmailMessage();
      
    $singleEmail1->targetObjectId $contactID;
      
    $singleEmail1->whatId $caseID;
      
    $singleEmail1->toAddresses 'ron@byressecurity.com';
      
    $singleEmail1->plainTextBody "Hello, your license is attached.";
      
    $singleEmail1->subject "Licensing Grants";
      
    $singleEmail1->saveAsActivity true;
      
    $singleEmail1->emailPriority EMAIL_PRIORITY_NORMAL;

      
    //Attachments, $file is the file in the directory the script is being ran from.

              
    $file 'test.txt';
              
    $sObject1 = new SObject();
              
    $sObject1->type 'Attachment';
              
    $handle fopen($file,'rb');
              
    $file_content fread($handle,filesize($file));
              
    fclose($handle);
              
    $sObject1->body $file_content;
              
    $createFields = array (
                
    'fileName' => $file,
                
    'body' => $file_content
              
    );
              
    $sObject1->fields $createFields;

      
    $singleEmail1->fileAttachments = array($createFields);

      echo 
    "***** Send Emails *****<br />";
      
    $emailResponse $mySforceConnection->sendSingleEmail(array($singleEmail1));

      echo 
    "<br />***** Lots of Awesome *****<br />";
      
    print_r($emailResponse);

    } catch (
    Exception $e) {
      echo 
    $mySforceConnection->getLastRequest();
      echo 
    $e->faultstring;
    }

    ?>
    Pretty simple, you should not need to encode the file being uploaded I think.

    One Problem though is that the email is not being listed under the case with the attachment. I wonder if SF tracks the email as an object here and the task much like a log entry...
    Last edited by Lantzvillian; 06-12-2009 at 01:40 PM.

  8. #8
    Hey Mike,

    uploaded a screenshot to maybe make things clearer. The GUI section is where emails go and have OUTBOUND EMAIL on them when you click on them.
    -These have [ref giberish ref] in 3 places.

    THE API emails are only in activity, and don't have attachments and are NOT listed in the Emails section of the case....



    I am looking with the APEX Explorer for references... It is in tasks like expected, but who what how, what references ( SF doesn't do joins like a regular db)

    Mind Discombobulating

    Edit**

    Came in the office this morning and had a brain wave. I googled Salesforce outbound messaging... I wonder if how sf sends its emails through the GUI calls the method notification()???? I did some quick reading, but I am not all that familiar with SOAP. Maybe you or somebody else here knows?
    Last edited by Lantzvillian; 06-15-2009 at 11:31 AM.

  9. #9
    Join Date
    May 2007
    Posts
    506
    Blog Entries
    3
    Quote Originally Posted by Lantzvillian View Post
    Hey Mike,

    Came in the office this morning and had a brain wave. I googled Salesforce outbound messaging... I wonder if how sf sends its emails through the GUI calls the method notification()???? I did some quick reading, but I am not all that familiar with SOAP. Maybe you or somebody else here knows?
    I work with the outbound messaging in some of our processes and do not send emails by either method man, so I do not know the answer to your question

    I know that the messages come in a XML format like this:

    Code:
        <?xml version="1.0" encoding="UTF-8"?>
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="XML Schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
        <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
         <OrganizationId>00DS0000000ErwzMAC</OrganizationId>
         <ActionId>04k400000004CYMAA2</ActionId>
         <SessionId xsi:nil="true"/>
         <EnterpriseUrl>https://cs1-api.salesforce.com/services/Soap/c/8.0/00DS0000000Erwz</EnterpriseUrl>
         <PartnerUrl>https://cs1-api.salesforce.com/services/Soap/u/8.0/00DS0000000Erwz</PartnerUrl>
         <Notification>
          <Id>04lS0000000tk6jIAA</Id>
          <sObject xsi:type="sf:OpportunityLineItem" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
           <sf:Id>00k40000004aqcGAAQ</sf:Id>
           <sf:Allocation__c>100.0</sf:Allocation__c>
           <sf:Competitors__c>TI</sf:Competitors__c>
           <sf:OpportunityId>00640000008HfSZAA0</sf:OpportunityId>
           <sf:Part_Outcome__c>Won</sf:Part_Outcome__c>
           <sf:Potential__c>3000000.0</sf:Potential__c>
           <sf:Price_Type__c>Quote</sf:Price_Type__c>
           <sf:PricebookEntryId>01u40000001E6mnAAC</sf:PricebookEntryId>
           <sf:Quantity>1.0</sf:Quantity>
           <sf:Socket_Freeze_Date__c>2009-03-27</sf:Socket_Freeze_Date__c>
           <sf:Socket_Label__c>MAXQ2021</sf:Socket_Label__c>
           <sf:UnitPrice>3.0</sf:UnitPrice>
          </sObject>
         </Notification>
        </notifications>
       </soapenv:Body>
      </soapenv:Envelope>
    Hope that makes sense

    ~Mike

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.0 RC1 PL1