load('wscurl.dll');
function sendmail() { }
var wsCurl = new Curl();
In this step, we will set the URL for the mail server. Note that in our example, we are using port 587 as opposed to the normal SMTP port 25. We are using 587 because we are using secure mail submission as defined in RFC4403. However, you should set your port to match the port on your mail server. The code is as follows:
wsCurl.setopt(Curl.CURLOPT_URL, "smtp://smtp.gmail.com:587");
In this step, we will upgrade the connection from plain text to Transport Layer Security (TLS). To do this, we will use the STARTTLS command.
wsCurl.setopt(Curl.CURLOPT_USE_SSL, Curl.USESSL_ALL);
There may be times when your server does not have a valid certificate. IN these cases, you can disable part of the TLS protection by using the following code to set the CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0.
wsCurl.setopt(Curl.CURLOPT_SSL_VERIFYPEER, 0); wsCurl.setopt(Curl.CURLOPT_SSL_VERIFYPEER, 0);
To add the certificate to libcurl, use the following code:
wsCurl.setopt(Curl.CURLOPT_CAINFO, "/path/to/certificate.pem");
The most common reason to have transport security is to protect your users'login credentials from theft. Use the following code to set user names and passwords.
wsCurl.setopt(CURLOPT_USERNAME, "user@example.com"); wsCurl.setopt(CURLOPT_PASSWORD, "Password");
Use the following code to set the envelope reverse path for the email. Please note that you must use brackets around the email address as shown in the example below. .
var translateLangIdentifier = "&target=";
Set the target language code itself. This will be a two-digit code and in our example, we will use English. A complete list of available language codes can be found in the Language Code Reference.
var translateLang = "en";
The following code will create the complete URL that we will use to make the call for a translation request. This is demonstrated as follows:
var completeURL = baseURL + textToConvert + sourceLangIdentifier + sourceLang + translateLangIdentifier + translateLang;
Now that you have the complete URL, you can make a request for translation as shown in the below example:
wsCurl.setopt(Curl.CURLOPT_URL, completeURL);
The final step in the process is to call the execute function. This will dispatch a response to your request. An example is shown below:
var response = wsCurl.exec();
In this example, the response will be in JSON, although you can set the response to be in HTML as well. A sample response based on the example iss shown below:
{ "data": { "translations": [ { "translatedText": "Bonjour tout le monde" } ] } }
To close the HTTP connection for wsCurl, use the following code:
wsCurl.close();
Your last step will be to remove any references for the garbage collection as shown below:
wsCurl=NULL;