sendpost 2.0.0
SendPost API
Keywords: OpenAPI, OpenAPI-Generator, SendPost API

    # Introduction  SendPost provides email API and SMTP relay which can be used not just to send &amp; measure but also alert &amp; optimised email sending.  You can use SendPost to:  * Send personalised emails to multiple recipients using email API   * Track opens and clicks  * Analyse statistics around open, clicks, bounce, unsubscribe and spam    At and advanced level you can use it to:  * Manage multiple sub-accounts which may map to your promotional or transactional sending, multiple product lines or multiple customers   * Classify your emails using groups for better analysis  * Analyse and fix email sending at sub-account level, IP Pool level or group level  * Have automated alerts to notify disruptions regarding email sending  * Manage different dedicated IP Pools so to better control your email sending  * Automatically know when IP or domain is blacklisted or sender score is down  * Leverage pro deliverability tools to get significantly better email deliverability &amp; inboxing   [&lt;img src&#x3D;\&quot;https://run.pstmn.io/button.svg\&quot; alt&#x3D;\&quot;Run In Postman\&quot; style&#x3D;\&quot;width: 128px; height: 32px;\&quot;&gt;](https://god.gw.postman.com/run-collection/33476323-e6dbd27f-c4a7-4d49-bcac-94b0611b938b?action&#x3D;collection%2Ffork&amp;source&#x3D;rip_markdown&amp;collection-url&#x3D;entityId%3D33476323-e6dbd27f-c4a7-4d49-bcac-94b0611b938b%26entityType%3Dcollection%26workspaceId%3D6b1e4f65-96a9-4136-9512-6266c852517e)   # Overview  ## REST API  SendPost API is built on REST API principles. Authenticated users can interact with any of the API endpoints to perform:  * **GET**- to get a resource  * **POST** - to create a resource  * **PUT** - to update an existing resource  * **DELETE** - to delete a resource   The API endpoint for all API calls is: &lt;code&gt;https://api.sendpost.io/api/v1&lt;/code&gt;   Some conventions that have been followed in the API design overall are following:   * All resources have either &lt;code&gt;/api/v1/subaccount&lt;/code&gt; or &lt;code&gt;/api/v1/account&lt;/code&gt; in their API call resource path based on who is authorised for the resource. All API calls with path &lt;code&gt;/api/v1/subaccount&lt;/code&gt; use &lt;code&gt;X-SubAccount-ApiKey&lt;/code&gt; in their request header. Likewise all API calls with path &lt;code&gt;/api/v1/account&lt;/code&gt; use &lt;code&gt;X-Account-ApiKey&lt;/code&gt; in their request header.  * All resource endpoints end with singular name and not plural. So we have &lt;code&gt;domain&lt;/code&gt; instead of domains for domain resource endpoint. Likewise we have &lt;code&gt;sender&lt;/code&gt; instead of senders for sender resource endpoint.  * Body submitted for POST / PUT API calls as well as JSON response from SendPost API follow camelcase convention  * All timestamps returned in response (created or submittedAt response fields) are UNIX nano epoch timestamp.   &lt;aside class&#x3D;\&quot;success\&quot;&gt; All resources have either &lt;code&gt;/api/v1/subaccount&lt;/code&gt; or &lt;code&gt;/api/v1/account&lt;/code&gt; in their API call resource path based on who is authorised for the resource. All API calls with path &lt;code&gt;/api/v1/subaccount&lt;/code&gt; use &lt;code&gt;X-SubAccount-ApiKey&lt;/code&gt; in their request header. Likewise all API calls with path &lt;code&gt;/api/v1/account&lt;/code&gt; use &lt;code&gt;X-Account-ApiKey&lt;/code&gt; in their request header. &lt;/aside&gt;   SendPost uses conventional HTTP response codes to indicate the success or failure of an API request.    * Codes in the &lt;code&gt;2xx&lt;/code&gt; range indicate success.   * Codes in the &lt;code&gt;4xx&lt;/code&gt; range indicate an error owing due to unauthorize access, incorrect request parameters or body etc.  * Code in the &lt;code&gt;5xx&lt;/code&gt; range indicate an eror with SendPost&#39;s servers ( internal service issue or maintenance )   &lt;aside class&#x3D;\&quot;info\&quot;&gt; SendPost all responses return &lt;code&gt;created&lt;/code&gt; in UNIX nano epoch timestamp.  &lt;/aside&gt;   ## Authentication  SendPost uses API keys for authentication. You can register a new SendPost API key at our [developer portal](https://app.sendpost.io/register).   SendPost expects the API key to be included in all API requests to the server in a header that looks like the following:   &#x60;X-SubAccount-ApiKey: AHEZEP8192SEGH&#x60;   This API key is used for all Sub-Account level operations such as:  * Sending emails  * Retrieving stats regarding open, click, bounce, unsubscribe and spam  * Uploading suppressions list  * Verifying sending domains and more  In addition to &lt;code&gt;X-SubAccount-ApiKey&lt;/code&gt; you also have another API Key &lt;code&gt;X-Account-APIKey&lt;/code&gt; which is used for Account level operations such as :  * Creating and managing sub-accounts  * Allocating IPs for your account  * Getting overall billing and usage information  * Email List validation  * Creating and managing alerts and more   &lt;aside class&#x3D;\&quot;notice\&quot;&gt; You must look at individual API reference page to look at whether &lt;code&gt;X-SubAccount-ApiKey&lt;/code&gt; is required or &lt;code&gt;X-Account-ApiKey&lt;/code&gt; &lt;/aside&gt;   In case an incorrect API Key header is specified or if it is missed you will get HTTP Response 401 ( Unauthorized ) response from SendPost.   ## HTTP Response Headers   Code           | Reason                 | Details ---------------| -----------------------| ----------- 200            | Success                | Everything went well 401            | Unauthorized           | Incorrect or missing API header either &lt;code&gt;X-SubAccount-ApiKey&lt;/code&gt; or &lt;code&gt;X-Account-ApiKey&lt;/code&gt; 403            | Forbidden              | Typically sent when resource with same name or details already exist 406            | Missing resource id    | Resource id specified is either missing or doesn&#39;t exist 422            | Unprocessable entity   | Request body is not in proper format 500            | Internal server error  | Some error happened at SendPost while processing API request 503            | Service Unavailable    | SendPost is offline for maintenance. Please try again later  # API SDKs  We have native SendPost SDKs in the following programming languages. You can integrate with them or create your own SDK with our API specification. In case you need any assistance with respect to API then do reachout to our team from website chat or email us at **hello@sendpost.io**   * [PHP](https://github.com/sendpost/sendpost_php_sdk)  * [Javascript](https://github.com/sendpost/sendpost_javascript_sdk)  * [Ruby](https://github.com/sendpost/sendpost_ruby_sdk)  * [Python](https://github.com/sendpost/sendpost_python_sdk)  * [Golang](https://github.com/sendpost/sendpost_go_sdk)   # API Reference  SendX REST API can be broken down into two major sub-sections:   * Sub-Account  * Account    Sub-Account API operations enable common email sending API use-cases like sending bulk email, adding new domains or senders for email sending programmatically, retrieving stats, adding suppressions etc. All Sub-Account API operations need to pass &lt;code&gt;X-SubAccount-ApiKey&lt;/code&gt; header with every API call.   The Account API operations allow users to manage multiple sub-accounts and manage IPs. A single parent SendPost account can have 100&#39;s of sub-accounts. You may want to create sub-accounts for different products your company is running or to segregate types of emails or for managing email sending across multiple customers of yours.   # SMTP Reference  Simple Mail Transfer Protocol (SMTP) is a quick and easy way to send email from one server to another. SendPost provides an SMTP service that allows you to deliver your email via our servers instead of your own client or server.  This means you can count on SendPost&#39;s delivery at scale for your SMTP needs.    ## Integrating SMTP    1. Get the SMTP &#x60;username&#x60; and &#x60;password&#x60; from your SendPost account.  2. Set the server host in your email client or application to &#x60;smtp.sendpost.io&#x60;. This setting is sometimes referred to as the external SMTP server or the SMTP relay.  3. Set the &#x60;username&#x60; and &#x60;password&#x60;.  4. Set the port to &#x60;587&#x60; (or as specified below).  ## SMTP Ports   - For an unencrypted or a TLS connection, use port &#x60;25&#x60;, &#x60;2525&#x60; or &#x60;587&#x60;.  - For a SSL connection, use port &#x60;465&#x60;  - Check your firewall and network to ensure they&#39;re not blocking any of our SMTP Endpoints.   SendPost supports STARTTLS for establishing a TLS-encrypted connection. STARTTLS is a means of upgrading an unencrypted connection to an encrypted connection. There are versions of STARTTLS for a variety of protocols; the SMTP version is defined in [RFC 3207](https://www.ietf.org/rfc/rfc3207.txt).   To set up a STARTTLS connection, the SMTP client connects to the SendPost SMTP endpoint &#x60;smtp.sendpost.io&#x60; on port 25, 587, or 2525, issues an EHLO command, and waits for the server to announce that it supports the STARTTLS SMTP extension. The client then issues the STARTTLS command, initiating TLS negotiation. When negotiation is complete, the client issues an EHLO command over the new encrypted connection, and the SMTP session proceeds normally.   &lt;aside class&#x3D;\&quot;success\&quot;&gt; If you are unsure which port to use, a TLS connection on port 587 is typically recommended. &lt;/aside&gt;   ## Sending email from your application   &#x60;&#x60;&#x60;javascript \&quot;use strict\&quot;;  const nodemailer &#x3D; require(\&quot;nodemailer\&quot;);  async function main() { // create reusable transporter object using the default SMTP transport let transporter &#x3D; nodemailer.createTransport({ host: \&quot;smtp.sendpost.io\&quot;, port: 587, secure: false, // true for 465, false for other ports auth: { user:  \&quot;&lt;username&gt;\&quot; , // generated ethereal user pass: \&quot;&lt;password&gt;\&quot;, // generated ethereal password }, requireTLS: true, debug: true, logger: true, });  // send mail with defined transport object try { let info &#x3D; await transporter.sendMail({ from: &#39;erlich@piedpiper.com&#39;, to: &#39;gilfoyle@piedpiper.com&#39;, subject: &#39;Test Email Subject&#39;, html: &#39;&lt;h1&gt;Hello Geeks!!!&lt;/h1&gt;&#39;, }); console.log(\&quot;Message sent: %s\&quot;, info.messageId); } catch (e) { console.log(e) } }  main().catch(console.error); &#x60;&#x60;&#x60;  For PHP   &#x60;&#x60;&#x60;php &lt;?php // Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception;  // Load Composer&#39;s autoloader require &#39;vendor/autoload.php&#39;;  $mail &#x3D; new PHPMailer(true);  // Settings try { $mail-&gt;SMTPDebug &#x3D; SMTP::DEBUG_CONNECTION;                  // Enable verbose debug output $mail-&gt;isSMTP();                                            // Send using SMTP $mail-&gt;Host       &#x3D; &#39;smtp.sendpost.io&#39;;                     // Set the SMTP server to send through $mail-&gt;SMTPAuth   &#x3D; true;                                   // Enable SMTP authentication $mail-&gt;Username   &#x3D; &#39;&lt;username&gt;&#39;;                           // SMTP username $mail-&gt;Password   &#x3D; &#39;&lt;password&gt;&#39;;                           // SMTP password $mail-&gt;SMTPSecure &#x3D; PHPMailer::ENCRYPTION_STARTTLS;         // Enable implicit TLS encryption $mail-&gt;Port       &#x3D; 587;                                    // TCP port to connect to; use 587 if you have set &#x60;SMTPSecure &#x3D; PHPMailer::ENCRYPTION_STARTTLS&#x60;  //Recipients $mail-&gt;setFrom(&#39;erlich@piedpiper.com&#39;, &#39;Erlich&#39;); $mail-&gt;addAddress(&#39;gilfoyle@piedpiper.com&#39;, &#39;Gilfoyle&#39;);  //Content $mail-&gt;isHTML(true);                                  //Set email format to HTML $mail-&gt;Subject &#x3D; &#39;Here is the subject&#39;; $mail-&gt;Body    &#x3D; &#39;This is the HTML message body &lt;b&gt;in bold!&lt;/b&gt;&#39;; $mail-&gt;AltBody &#x3D; &#39;This is the body in plain text for non-HTML mail clients&#39;;  $mail-&gt;send(); echo &#39;Message has been sent&#39;;  } catch (Exception $e) { echo \&quot;Message could not be sent. Mailer Error: {$mail-&gt;ErrorInfo}\&quot;; } &#x60;&#x60;&#x60; For Python &#x60;&#x60;&#x60;python #!/usr/bin/python3  import sys import os import re  from smtplib import SMTP import ssl  from email.mime.text import MIMEText  SMTPserver &#x3D; &#39;smtp.sendpost.io&#39; PORT &#x3D; 587 sender &#x3D;     &#39;erlich@piedpiper.com&#39; destination &#x3D; [&#39;gilfoyle@piedpiper.com&#39;]  USERNAME &#x3D; \&quot;&lt;username&gt;\&quot; PASSWORD &#x3D; \&quot;&lt;password&gt;\&quot;  # typical values for text_subtype are plain, html, xml text_subtype &#x3D; &#39;plain&#39;  content&#x3D;\&quot;\&quot;\&quot;\ Test message \&quot;\&quot;\&quot;  subject&#x3D;\&quot;Sent from Python\&quot;  try: msg &#x3D; MIMEText(content, text_subtype) msg[&#39;Subject&#39;]&#x3D; subject msg[&#39;From&#39;]   &#x3D; sender  conn &#x3D; SMTP(SMTPserver, PORT) conn.ehlo() context &#x3D; ssl.create_default_context() conn.starttls(context&#x3D;context)  # upgrade to tls conn.ehlo() conn.set_debuglevel(True) conn.login(USERNAME, PASSWORD)  try: resp &#x3D; conn.sendmail(sender, destination, msg.as_string()) print(\&quot;Send Mail Response: \&quot;, resp) except Exception as e: print(\&quot;Send Email Error: \&quot;, e) finally: conn.quit()  except Exception as e: print(\&quot;Error:\&quot;, e) &#x60;&#x60;&#x60; For Golang &#x60;&#x60;&#x60;go package main  import ( \&quot;fmt\&quot; \&quot;net/smtp\&quot; \&quot;os\&quot; )  // Sending Email Using Smtp in Golang  func main() {  username :&#x3D; \&quot;&lt;username&gt;\&quot; password :&#x3D; \&quot;&lt;password&gt;\&quot;  from :&#x3D; \&quot;erlich@piedpiper.com\&quot; toList :&#x3D; []string{\&quot;gilfoyle@piedpiper.com\&quot;} host :&#x3D; \&quot;smtp.sendpost.io\&quot; port :&#x3D; \&quot;587\&quot; // recommended  // This is the message to send in the mail msg :&#x3D; \&quot;Hello geeks!!!\&quot;  // We can&#39;t send strings directly in mail, // strings need to be converted into slice bytes body :&#x3D; []byte(msg)  // PlainAuth uses the given username and password to // authenticate to host and act as identity. // Usually identity should be the empty string, // to act as username. auth :&#x3D; smtp.PlainAuth(\&quot;\&quot;, username, password, host)  // SendMail uses TLS connection to send the mail // The email is sent to all address in the toList, // the body should be of type bytes, not strings // This returns error if any occured. err :&#x3D; smtp.SendMail(host+\&quot;:\&quot;+port, auth, from, toList, body)  // handling the errors if err !&#x3D; nil { fmt.Println(err) os.Exit(1) }  fmt.Println(\&quot;Successfully sent mail to all user in toList\&quot;) }  &#x60;&#x60;&#x60; For Java &#x60;&#x60;&#x60;java // implementation &#39;com.sun.mail:javax.mail:1.6.2&#39;  import java.util.Properties;  import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage;  public class SMTPConnect {  // This address must be verified. static final String FROM &#x3D; \&quot;erlich@piedpiper.com\&quot;; static final String FROMNAME &#x3D; \&quot;Erlich Bachman\&quot;;  // Replace recipient@example.com with a \&quot;To\&quot; address. If your account // is still in the sandbox, this address must be verified. static final String TO &#x3D; \&quot;gilfoyle@piedpiper.com\&quot;;  // Replace smtp_username with your SendPost SMTP user name. static final String SMTP_USERNAME &#x3D; \&quot;&lt;username&gt;\&quot;;  // Replace smtp_password with your SendPost SMTP password. static final String SMTP_PASSWORD &#x3D; \&quot;&lt;password&gt;\&quot;;  // SMTP Host Name static final String HOST &#x3D; \&quot;smtp.sendpost.io\&quot;;  // The port you will connect to on SendPost SMTP Endpoint. static final int PORT &#x3D; 587;  static final String SUBJECT &#x3D; \&quot;SendPost SMTP Test (SMTP interface accessed using Java)\&quot;;  static final String BODY &#x3D; String.join( System.getProperty(\&quot;line.separator\&quot;), \&quot;&lt;h1&gt;SendPost SMTP Test&lt;/h1&gt;\&quot;, \&quot;&lt;p&gt;This email was sent with SendPost using the \&quot;, \&quot;&lt;a href&#x3D;&#39;https://github.com/eclipse-ee4j/mail&#39;&gt;Javamail Package&lt;/a&gt;\&quot;, \&quot; for &lt;a href&#x3D;&#39;https://www.java.com&#39;&gt;Java&lt;/a&gt;.\&quot; );  public static void main(String[] args) throws Exception {  // Create a Properties object to contain connection configuration information. Properties props &#x3D; System.getProperties(); props.put(\&quot;mail.transport.protocol\&quot;, \&quot;smtp\&quot;); props.put(\&quot;mail.smtp.port\&quot;, PORT); props.put(\&quot;mail.smtp.starttls.enable\&quot;, \&quot;true\&quot;); props.put(\&quot;mail.smtp.debug\&quot;, \&quot;true\&quot;); props.put(\&quot;mail.smtp.auth\&quot;, \&quot;true\&quot;);  // Create a Session object to represent a mail session with the specified properties. Session session &#x3D; Session.getDefaultInstance(props);  // Create a message with the specified information. MimeMessage msg &#x3D; new MimeMessage(session); msg.setFrom(new InternetAddress(FROM,FROMNAME)); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO)); msg.setSubject(SUBJECT); msg.setContent(BODY,\&quot;text/html\&quot;);  // Create a transport. Transport transport &#x3D; session.getTransport();  // Send the message. try { System.out.println(\&quot;Sending...\&quot;);  // Connect to SendPost SMTP using the SMTP username and password you specified above. transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);  // Send the email. transport.sendMessage(msg, msg.getAllRecipients()); System.out.println(\&quot;Email sent!\&quot;);  } catch (Exception ex) {  System.out.println(\&quot;The email was not sent.\&quot;); System.out.println(\&quot;Error message: \&quot; + ex.getMessage()); System.out.println(ex); } // Close and terminate the connection. } } &#x60;&#x60;&#x60;  Many programming languages support sending email using SMTP. This capability might be built into the programming language itself, or it might be available as an add-on, plug-in, or library. You can take advantage of this capability by sending email through SendPost from within application programs that you write.  We have provided examples in Python3, Golang, Java, PHP, JS.