SMTP web API

Our SMTP API is a great way to tailor turboSMTP’s outgoing mail server as you prefer, intergrating it elswhere.

At the moment we provide a Send method that allows you to create a script to run turboSMTP and send transactional emails (login confirmations, welcome messages, receipts etc.) via web.

So if you have a website or an app and you need to send a message directly from there, you can implement this API in your script and manage it easily.

Below you will find the full documentation. We are currently developing new API methods, so stay tuned for more! 

Download the sample source code

PHP C# Java Python Perl Ruby


Send (Beta 1.0)

The service allows you to send an email

Index

  • Parameters
  • POST request
  • MIME body message
  • Example of email sending (curl)
  • Example of email sending (PHP)
  • TurboApiClient (PHP)
  • Download source code example (PHP)

 

Parameters [top]

Parameters Mandatory Bonds Descriptions
to Yes Valid email addresses. Recipients list. In case of multiple recipients, the addresses must be separated by a comma.
subject No Max 700 characters string. The subject of the email to be sent.
from Yes Valid email address. The sender address of the email to be sent.
bcc No Valid email addresses. Blind carbon copy list. In case of multiple recipients, the addresses must be separated by a comma.
cc No Valid email address Carbon copy list. In case of multiple recipients, the addresses must be separated by a comma.
content No Email’s textual content.
html_content No Email’s HTML content.
custom_headers No Valid JSON format. Key collection value of custom headers to put in the email. Example:

 {"X-key1":"value1", "X-key2":"value2"}
mime_raw No MIME standard format. MIME type message, replacing content and html_content.

Post request [top]

Url

https://api.turbo-smtp.com/api/mail/send

The user authentication takes place through the following parameters:

  • authuser: Username
  • authpass: Password

The authentication data can be handled as GET and POST parameters, or as the https request’s headers.

Example of Post request

from:from_address@domain.com
to:to1_address@domain.com,to2_address@domain.com
cc:cc1_address@domain.com,cc2_address@domain.com
bcc:bcc1_address@domain.com,bcc2_address@domain.com
subject:subject of email
content:text content of email
html_content: html content of email
custom_headers:{"X-key1":"value1", "X-key2":"value2"}

Post response

The server’s responses are in JSON format. The object’s members are:

  • message: outcome of the response “OK” in case of success, “error” in case of error
  • errors: (only in case of error) array containing the error messages

 

Success response

 { "message":"OK" }

Error response

 { "message": "error","errors": ["error message",...]}

Example of an error response

 { "message": "error","errors": ["'broken@@@Address.@@' recipient email not valid" , "'broken2@@@Address2.@@222' bcc email not valid"]}

NOTE: this error is referred to a malformed email. We don’t do any hard/soft bounce check at this stage, since the API only puts your email in our queues. If you want to know if a contact bounced you need to check it in the dashboard reports.

MIME type body message [top]

In case you want to send as the email’s body a MIME type message, you must send it as a POST parameter named “mime”.

In this case the content and content_html parameters are ignored. The message must be standard. If you send a message without header you need in any case, as required by specification, to let an empty line before the body.

This parameter allows to send a file inside the message.

Example of a (curl) email sending [top]

Sample code to send an email using the curl command.

Email dispatch

Let’s send an email using the authentication key obtained from the previous call.

curl --Header "authuser:_username" --Header "authpass:_password" --data "to=john.smith@domain.com&subject=email subject string&from=john.smith@domain.com&bcc=mark.davies@domain.com&cc=mary.davies@domain.com&content=content email&html_content=html content of email" https://api.turbo-smtp.com/api/mail/send

Example of (PHP) email sending [top]

Sample PHP code to send an email using our API.

Source code
require_once "TurboApiClient.php";

// creation of the email to be sent
$email = new Email();
$email->setFrom("john.smith@domain.com");
$email->setToList("mark.davies@domain.com, bruce.campbell@domain.com");
$email->setCcList("mary.davies@domain.com, mary.smith@domain.com");
$email->setBccList("maria.campbell@domain.com, don.smith@domain.com");	
$email->setSubject("subject");
$email->setContent("content");
$email->setHtmlContent("html content");
$email->addCustomHeader('X-FirstHeader', "value");
$email->addCustomHeader('X-SecondHeader', "value");
$email->addCustomHeader('X-Header-to-be-removed', 'value');
$email->removeCustomHeader('X-Header-to-be-removed);

// creation of a client that connects with turbo-smtp APIs
$turboApiClient = new TurboApiClient("_username", "_password");

// email sending
$response = $turboApiClient->sendEmail($email);

// display of the operation's outcome
var_dump($response);						

TurboApiClient (PHP) [top]

A simple client useful to connect with our API.

source code
require_once  "TurboClient.php";
require_once  "Email.php";

class TurboApiClient{
	
	protected $username;
	protected $password;
	private $serverUrl = "https://api.turbo-smtp.com/api";

	public function __construct($username, $password) {
       $this->username = $username;
	   $this->password = $password;
   }

	protected function authorize(){
		try {
			$api = new TurboClient($this->serverUrl, $this->username, $this->password);
			return $api;
		} catch (Pest_Forbidden $ex) {
		    return null;

		}
	}

	public function sendEmail($email){
		$api = $this->authorize();
		if($api){
			try {
			    	$response = $api->post(
			    		'/mail/send',
			       		$email->getPostParameters()
			    	);
			    return $response;
			} catch (Pest_NotFound $e) {
			    return $e;
			}
		}else{
			return "Authorization error";
		}
	}
};

Download the sample source code [top]

PHP C# Java Python Perl Ruby