Send Email - JSON ( Edit )
JSON/Email send – this API can be use to send emails.
Host: https://api.pepipost.com
Content-Type: application/json
POST /api/web.send.json HTTP/1.1
{
"api_key": "string",
"email_details": {
"fromname": "yourfromname",
"subject": "this is test email subject",
"from": "from@example.com",
"content": "<p> hi, this is a test email sent via Pepipost JSON API.</p>"
},
"recipients": [
"recipient@example.com"
]
}
Click here to try the above example with our online API console
HTTP/1.1 200 OK
{"message":"SUCCESS","errorcode": "0" ,"errormessage":""}
In order to send personalized content email using Pepipost API, you need to first provide the attribute in your API call along with the place-holders used inside of your HTML content. Like below given example:
Your API Call
POST /api/web.send.json HTTP/1.1
{
"api_key":"yourapikey",
"email_details":{
"fromname":"sender name",
"subject":"test email subject",
"from":"from@example.com",
"content":"<p>Hi [%NAME%], your current balance as on today is [%ACCOUNT_BAL%].</p>"
},
"recipients":["mike@example.com","joe@example.com"],
"attributes":{
"NAME":["Mike","Joe"],
"ACCOUNT_BAL":["100","200"]
}
}
Click here to try the above example with our online API console
**Mail received by Mike **
<p>Hi Mike, your current balance as on today is 100.</p>
**Mail received by Joe **
<p>Hi Joe, your current balance as on today is 200.</p>
Host: https://api.pepipost.com
Content-Type: application/json
POST /api/web.send.json HTTP/1.1
{
"api_key":"yourapikey",
"email_details":{
"fromname":"sender name",
"subject":"test email subject",
"from":"from@example.com",
"replytoid": "replytoid@example.com",
"content":"<p>Hi [%NAME%], This is a test email sent using Pepipost JSON/Email API</p>"
},
"tags": "AccountDeactivation, Verification",
"X-APIHEADER": ["ID3","ID2"],
"settings":{
"footer":"1",
"clicktrack":"1",
"opentrack":"1",
"unsubscribe":"1",
"bcc":"sac@test.com",
"attachmentid":"1,3,4",
"template":"101",
},
"recipients":["recipient1@example.com","recipient2@example.com"],
"attributes":{
"NAME":["NameOfFirstRecipient","NameOfSecondRecipient"],
"AGE":["20","30"]
},
"files": {
"attachment_example1.txt": "VGhpcyBpcyB0aGUgY29udGVudCBvZiBhIHRlc3QgZmlsZS4K",
"attachment_example2.txt": "VGhpcyBpcyB0aGUgY29udGVudCBvZiBhIHRlc3QgZmlsZSAyLgo="
}
}
Click here to try the above example with our online API console
** NOTES **
- The fields "NAME" and "AGE" are user defined. One can use any alphanumeric attribute name.
- The fields "attachment_example1.txt" and "attachment_example2.txt" are user defined. One can use any alphanumeric filename.
- The value of field "files" needs to be encoded in base64 encoding format. You can attach various types of files including pdf, png, etc in the same as shown above. However, the above example uses txt file example becauase the base64 for other file types (like pdf) will be large and make the example unreadable.
HTTP/1.1 200 OK
{"message":"SUCCESS","errorcode": "0" ,"errormessage":""}
Name | Required | In | Type | Description |
---|---|---|---|---|
api_key | Yes | query | string | Your API Key |
data | Yes | body | Data | Data in JSON format |
Name | Type | Required | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
api_key | string | Yes | Your secret API Key | ||||||||||||||||||||||||||||||||
email_details | struct | Yes |
|
||||||||||||||||||||||||||||||||
X-APIHEADER | array[string] | No | This is the user defined ids in order to uniquely identify each emails. | ||||||||||||||||||||||||||||||||
settings | struct | No |
|
||||||||||||||||||||||||||||||||
recipients | array[string] | Yes | Array of recipients email addresses, to whom the mail will be sent. | ||||||||||||||||||||||||||||||||
attributes | struct | No |
|
||||||||||||||||||||||||||||||||
files | struct | No |
|
Name | Description |
---|---|
message | Its can have only 2 values - "SUCCESS" or "ERROR" |
errorcode | Pepipost API error code. Its value will be - 0 (zero) in case of success. In case of error it will be non-zero integer value. |
errormessage | Error specific error messages. |
Its recommended to use Peipost SDK for PHP in order to integrate Pepipost services with applications written in PHP. You can get Pepipost SDK for PHP by clicking here .
<?php
require_once __DIR__.'/vendor/autoload.php';
use PepipostAPIV10Lib\Controllers\Email;
$email = new Email();
$data = array(
'api_key' => 'yoursecretapikey',
'recipients' => array('recipient@example.com'),
'email_details' => array(
'content' => 'this mail is sent via PHP SDK',
'from' => 'from@example.com',
'subject' => 'this mail is sent via PHP SDK',
'fromname' => 'SDK Sender Name ',
)
);
try {
$response = $email->sendJson( $data );
if(empty($response->errorcode)){
print "Email sent successfully.\n";
}
else {
print "Email sent Failed.\n";
print "errormessage(" . $response->errormessage . ") \n";
print "errorcode(" . $response->errorcode . ").\n";
}
}
catch(Exception $e){
print 'Call failed due to unhandled exception/error('. $e->getMessage().')'."\n";
}
<?php
require_once __DIR__.'/vendor/autoload.php';
use PepipostAPIV10Lib\Controllers\Email;
$email = new Email();
$data = array(
'api_key' => 'yoursecretkey',
'recipients' => array('recipient1@example.com','recipient2@example.com'),
'email_details' => array(
'from' => 'from@example.com',
'subject' => 'Hi [% NAME %], here is your account balance.',
'content' => '<p>Hi [%NAME%],</p><p>Your account balance is [% ACCOUNT_BAL %].</p>',
'fromname' => 'SDK Sender Name ',
'replytoid' => 'replyto@example.com',
),
'tags' => 'AccountDeactivation, Verification',
'X-APIHEADER' => array('UserID1','UserID2'),
'settings' => array(
'footer' => true,
'clicktrack' => true,
'opentrack' => true,
'unsubscribe' => true,
'bcc' => 'bcc@example.com',
),
'attributes' => array(
'NAME' => array('NameOfRecipient1','NameOfRecipient2'),
'ACCOUNT_BAL' => array('100','200'),
),
'files' => array(
'example_attachment1.txt' => base64_encode(trim(file_get_contents('/path/to/file.txt'))),
'example_attachment2.pdf' => base64_encode(trim(file_get_contents('/path/to/file.pdf'))),
),
);
try {
$response = $email->sendJson( $data );
//var_dump($response);
if(empty($response->errorcode)){
print "Email sent successfully.\n";
}
else {
print "Email sent Failed.\n";
print "errormessage(" . $response->errormessage . ") \n";
print "errorcode(" . $response->errorcode . ").\n";
}
}
catch(Exception $e){
print 'Call failed due to unhandled exception/error('. $e->getMessage().')'."\n";
}
Its recommended to use Peipost SDK for Python in order to integrate Pepipost services with applications written in Python. You can get Pepipost SDK for Python by clicking here .
from PepipostAPIV10Lib.Controllers.Email import *
import json
controller = Email()
#data = ()
data = {
'api_key' : 'yoursecretapikey',
'recipients' : ['recipient1@example.com','recipient2@example.com'],
'email_details' : {
'fromname' : 'sender name',
'subject' : 'test email subject sent using Pepipost SDK - Python',
'from' : 'from@example.com',
'content' : '<p>This is a test email sent using Pepipost JSON/Email Python SDK</p>'
}
}
response = controller.send(data)
print response
Its recommended to use Peipost SDK for Ruby in order to integrate Pepipost services with applications written in Ruby. You can get Pepipost SDK for Ruby by clicking here .
require 'pepipost_apiv_10'
data = {
"api_key"=>"yoursecretapikey",
"recipients"=> ["recipient1@example.com","recipient2@example.com"],
"email_details" => {
"fromname" => "sender name",
"subject" => "This is a test email sent usig Pepipost SDK for Ruby",
"from" => "from@example.com",
"content" => "<p>This is a test email sent using Pepipost SDK for Ruby</p>",
}
}
email = PepipostApiv10::Email.new
response = email.send data
print response
Its recommended to use Peipost SDK for NodeJS in order to integrate Pepipost services with applications written in NodeJS.
You can install it using npm "npm install pepipost-sdk-nodejs".
You can get its source code by clicking here .
var PepipostSDK = require('pepipost-sdk-nodejs');
var Email = PepipostSDK.EmailController;
var data = {
"api_key": "yoursecretapikey",
"email_details": {
"fromname": "yourfromname",
"subject": "this is test email subject",
"from": "from@example.com",
"content": "<p> hi, this is a test email sent via Pepipost JSON API.</p>"
},
"recipients": [
"recipient@example.com"
]
};
Email.send(data,callback_mail_sent);
function callback_mail_sent(err_msg,parsed,context){
if(parsed.errorcode==0){
console.log("mail sent successfully.\n");
}
else{
console.log("Email sent Failed.\n");
console.log("errormessage("+parsed.errormessage+")\n");
console.log("errorcode("+parsed.errorcode+")\n");
}
}
Nodemailer is a famous NodeJS library to send email.
You can know more about Nodemailer by clicking here .
Please follow the below steps, in order to integerate Pepipost with Nodemailer:
You can install it using npm "npm install nodemailer".
var nodemailer = require('nodemailer');
//below var smtpTransport not required for Nodemailer version equal or below v0.7.1
var smtpTransport = require("nodemailer-smtp-transport");
// Create a SMTP transport object
var transport = nodemailer.createTransport(smtpTransport( {
host: "smtp.pepipost.com",
port: 2525,
auth: {
user: "yoursmtpusername",
pass: "yoursmtppassword"
}
}));
/*
//Use this code for Nodemailer version equal or below v0.7.1
var transport = nodemailer.createTransport("SMTP", {
//service: 'Pepipost',
host: "smtp.pepipost.com",
port: 2525,
auth: {
user: "yoursmtpusername",
pass: "yoursmtppassword"
}
});
*/
console.log('SMTP Configured');
// Message object
var message = {
// sender info
from: 'Sender Name <sender@example.com>',
// Comma separated list of recipients
to: '"Receiver Name" <recipient@example.com>',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔',
// plaintext body
text: 'Test mail sent using Nodemailer with Pepipost',
// HTML body
html:'<p><b>Hello</b> Test mail sent using Nodemailer with Pepipost</p>'+
'<p>Thank you.</p>'
//For adding X-APIHEADER, uncomment the blow lines
/**
,headers: {
'X-APIHEADER':'userid1'
}
*/
};
console.log('Sending Mail');
transport.sendMail(message, function(error){
if(error){
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
Its recommended to use Peipost SDK for Java in order to integrate Pepipost services with applications written in Java. You can get Pepipost SDK for Java by clicking here .
import io.swagger.client.*;
import io.swagger.client.auth.*;
import io.swagger.client.model.*;
import io.swagger.client.api.EmailApi;
import java.io.File;
import java.util.*;
public class Example {
public static void main(String[] args) {
//Getting the SDK object
EmailApi pepipostSDK = new EmailApi();
//Getting the data object
Emailv1 data = new Emailv1(); // Emailv1 | Data in JSON format
//setting the apikey
data.setApiKey("yoursecretapikey");
//setting the data
EmailDetails email_details = new EmailDetails(); // Emailv1 | Data in JSON format
email_details.setFromname("yourfromname");
email_details.setFrom("from@example.com");
email_details.subject("This is the test email subject sent via Pepipost Java SDK");
email_details.setContent("<p> hi, this is a test email sent via Pepipost Java SDK using its JSON API.</p>");
data.setEmailDetails(email_details);
//adding recipients
List<String> recipients = new ArrayList<String>();
recipients.add("to@example.com");
data.setRecipients(recipients);
//making the call
try {
pepipostSDK.apiWebSendJsonPost(data);
System.out.println("Email sent successfully.");
} catch (ApiException e) {
System.out.println("Exception occurred while calling Pepipost API");
System.out.println("Errormessage("+e.getMessage()+")");
System.out.println("Errorcode("+e.getCode()+")");
//e.printStackTrace();
}
}
}
Its recommended to use Peipost SDK for Perl in order to integrate Pepipost services with applications written in Perl. You can get Pepipost SDK for Perl by clicking here .
#!/usr/bin/perl
use lib 'lib';
use strict;
use warnings;
# load the API package
use WWW::Pepipost::EmailApi;
# load the models
use WWW::Pepipost::Object::Attributes;
use WWW::Pepipost::Object::EmailDetails;
use WWW::Pepipost::Object::Emailv1;
use WWW::Pepipost::Object::Files;
use WWW::Pepipost::Object::Settings;
# for displaying the API response data
use Data::Dumper;
my $email = WWW::Pepipost::EmailApi->new();
my $data = WWW::Pepipost::Object::Emailv1->new(); # Emailv1 | Data in JSON format
$data->{'api_key'} = 'yoursecretkey';
$data->{'recipients'} = ['recipient@example.com'];
$data->{'email_details'}{'subject'} = 'This is a test email subject sent using Pepipost SDK for Perl';
$data->{'email_details'}{'from'} = 'from@example.com';
$data->{'email_details'}{'content'} = 'This is a test email content sent using Pepipost SDK for Perl';
eval {
my $response = $email->send(data => $data);
print "response($response)\n";
};
if ($@) {
warn "Exception when calling EmailApi->send: $@\n";
}
Its recommended to use Peipost SDK for C# in order to integrate Pepipost services with applications written in C#. You can get Pepipost SDK for C# by clicking here .
using System;
using IO.Swagger.Api;
using IO.Swagger.Client;
using IO.Swagger.Model;
using Newtonsoft.Json;
namespace youconsoleapp
{
class MainClass
{
public static void Main (string[] args)
{
//Prepare the data
Emailv1 data = new Emailv1 ();
data.ApiKey = "yoursecretapikey";
//email_details Model
EmailDetails email_details = new EmailDetails ();
email_details.Fromname = "sender name";
email_details.From = "from@example.com";
email_details.Subject = "Test email sent using Pepiopst Csharp SDK";
email_details.Content = "<p>This email is sent using Pepipost CSharp SDK</p>";
System.Collections.Generic.List<string> recipients = new System.Collections.Generic.List<string> {"recipient@example.com"};
//Combine all
data.Recipients = recipients;
data.EmailDetails = email_details;
//Call the API method
EmailApi email = new EmailApi ();
//For debug print outgoing json
//String data_json = JsonConvert.SerializeObject (data);
//System.Console.WriteLine ("Data JSON "+ data_json);
var response = email.CreateApiWebSendJson (data);
System.Console.WriteLine ("response"+response.ToString());
}
}
}