Liquid UI - WS Reference Library

WSCurl Send Mail


Runs On

  SAP GUI Android iOS WM Web
Direct Connect          
Liquid UI Server Connect        


Send email using WSCurl from SAP.

User Interface

Log into SAP and on the SAP Easy Access Screen click on the ‘Send Mail’ toolbar pushbutton.

Liquid UI Script


// Function to check if the string value is blank
function isBlank(jvar) {
    if (jvar==void 0 || jvar=="" || jvar==null) {
        return true;
    } else {
        return false;

function sendmail(){   
   /* Initialize the Curl object for making the call*/
   var wsCurl = new Curl();
   /* This is the URL for your mailserver. Note the use of port 587 here,
     * instead of the normal SMTP port (25). Port 587 is commonly used for
     * secure mail submission (see RFC4403), but you should use whatever
     * matches your server configuration. */
    // wsCurl.setopt(Curl.CURLOPT_URL, "smtp://");

    wsCurl.setopt(Curl.CURLOPT_URL, "smtp://");
    /* In this example, we'll start with a plain text connection, and upgrade
     * to Transport Layer Security (TLS) using the STARTTLS command. Be careful
     * of using Curl.USESSL_TRY here, because if TLS upgrade fails, the transfer
     * will continue anyway - see the security discussion in the libcurl
     * tutorial for more details. Available 2nd Parameters are Curl.USESSL_NONE(0),
    * Curl.USESSL_TRY(1), Curl.USESSL_CONTROL(2) or Curl.USESSL_ALL(3)*/

    wsCurl.setopt(Curl.CURLOPT_USE_SSL, Curl.USESSL_ALL);

    /* If your server doesn't have a valid certificate, then you can disable
     * part of the Transport Layer Security protection by setting the
     *   wsCurl.setopt(Curl.CURLOPT_SSL_VERIFYPEER, 0);
     *   wsCurl.setopt(Curl.CURLOPT_SSL_VERIFYHOST, 0);
     * That is, in general, a bad idea. It is still better than sending your
     * authentication details in plain text though.
     * Instead, you should get the issuer certificate (or the host certificate
     * if the certificate is self-signed) and add it to the set of certificates
     * that are known to libcurl using CURLOPT_CAINFO.
    *    wsCurl.setopt(Curl.CURLOPT_CAINFO, "/path/to/certificate.pem");

    /* A common reason for requiring transport security is to protect
     * authentication details (user names and passwords) from being "snooped"
     * on the network. Here is how the user name and password are provided: */
    // wsCurl.setopt(Curl.CURLOPT_USERNAME, "");
    // wsCurl.setopt(Curl.CURLOPT_PASSWORD, "P@ssw0rd");

    wsCurl.setopt(Curl.CURLOPT_USERNAME, "");
    wsCurl.setopt(Curl.CURLOPT_PASSWORD, " ");      // Enter the Password

    /* value for envelope reverse-path. '<' '>' are REQUIRED around the email addr*/
    // wsCurl.setopt(Curl.CURLOPT_MAIL_FROM, "<>");

    wsCurl.setopt(Curl.CURLOPT_MAIL_FROM, "<>");
    /* Add two recipients, in this particular case they correspond to the
     * To: and Cc: addressees in the header, but they could be any kind of
     * recipient. */
    // wsCurl.slist_append("<>");
    // wsCurl.slist_append("<>");

   /* Set the curl object to attach the recepients added above
    * The second parameter is a REQUIRED string to maintain the syntax,
    *  however it has no effect on the execution*/ 
   // wsCurl.setopt(Curl.CURLOPT_MAIL_RCPT, "recipients");

    /* Since the traffic will be encrypted, it is very useful to turn on debug
     * information within libcurl to see what is happening during the transfer.

    wsCurl.setopt(Curl.CURLOPT_VERBOSE, 1);
   /* Set the buffer header and the data for the e-mail that is being sent*/
   var email = ["Date: Mon, 29 Nov 2010 21:54:29 +1100\n",
               "To: <>\n",
               "From: <>\n",
               "Subject: WS embedded SMTP TLS MESSAGE\n",
               "\n", /* empty line to divide headers from body, see RFC5322 */
               "The body of the message starts here.\n",
               "It could be a lot of lines, could be MIME encoded, whatever.\n",
               "Check RFC5322.\n", NULL ];
   /* In this case, we're using a callback function to specify the data. You
     * could just use the CURLOPT_READDATA option to specify a var to read from*/

    wsCurl.setopt(Curl.CURLOPT_READDATA, email);
   /* Final step is to call execute to dispatch email*/
   /* Clean up the recepient list*/
   /* Close the smtp connection for the mail server*/
   /* Remove any reference for Garbage Collection*/
   wsCurl= NULL;

// User Interface
pushbutton([TOOLBAR], 'Send Mail', '?', {"process":sendmail});