Product•2 min read

Sending Marketing Campaigns with the Piisend Email API

Discover how to effectively send marketing and promotional email campaigns using the Piisend API, ensuring high deliverability and compliance with best practices for newsletters and bulk sends.

Sending Marketing Campaigns with the Piisend Email API

Section 1

Unifying Transactional and Marketing Emails with Piisend

Piisend's robust email API is designed to handle both your critical transactional emails and your broader marketing campaigns. While both types of emails use the same powerful infrastructure, it's crucial to understand their distinct requirements to maintain optimal deliverability and sender reputation. This guide will walk you through best practices for sending promotional content and newsletters, leveraging the flexibility of the Piisend API.

http
1POST https://api.piisend.com/api/v1/emails
2Authorization: Bearer YOUR_API_KEY
3Content-Type: application/json
4
5{
6 "to": ["marketing@example.com"],
7 "subject": "Exciting New Features from Piisend!",
8 "html": "<html><body><h1>Check out our latest updates!</h1><p>We've added incredible new features to enhance your email experience.</p></body></html>",
9 "text": "Check out our latest updates! We've added incredible new features to enhance your email experience."
10}

Section 2

For marketing emails, explicit user consent is paramount. Piisend helps you comply with regulations by supporting the List-Unsubscribe header, which allows recipients to easily opt-out directly from their email client. This not only improves user experience but also protects your sender reputation by reducing spam complaints. Always ensure your email lists are clean and up-to-date to avoid unnecessary bounces and maintain high deliverability for your promotional campaigns.

python
1import requests
2
3api_key = "YOUR_API_KEY"
4url = "https://api.piisend.com/api/v1/emails"
5headers = {
6 "Authorization": f"Bearer {api_key}",
7 "Content-Type": "application/json"
8}
9payload = {
10 "to": ["subscriber@example.com"],
11 "subject": "Your Monthly Piisend Newsletter",
12 "html": "<html><body><p>Hello! Here's your latest update from Piisend.</p></body></html>",
13 "text": "Hello! Here's your latest update from Piisend.",
14 "headers": {
15 "List-Unsubscribe": "<mailto:unsubscribe@example.com?subject=unsubscribe>, <https://example.com/unsubscribe/{{user_id}}>"
16 }
17}
18
19response = requests.post(url, headers=headers, json=payload)
20
21print(response.status_code)
22print(response.json())

Section 3

Leveraging Templates for Dynamic Marketing Content

Piisend's email templates are ideal for creating engaging marketing campaigns without repetitive code. You can design beautiful newsletters and promotional emails, then populate them with dynamic content using merge variables. This approach ensures consistency and efficiency across all your marketing communications, allowing you to personalize messages at scale for your audience. Utilize the template_id and template_vars fields to send rich, personalized content effortlessly.

javascript
1const fetch = require('node-fetch');
2
3const apiKey = 'YOUR_API_KEY';
4const url = 'https://api.piisend.com/api/v1/emails';
5
6const payload = {
7 to: ['customer@example.com'],
8 subject: 'Exclusive Offer Just For You!',
9 template_id: 'tpl_your_marketing_template_id',
10 template_vars: {
11 customer_name: 'Jane Doe',
12 offer_code: 'SAVE20',
13 discount_percentage: '20%'
14 }
15};
16
17fetch(url, {
18 method: 'POST',
19 headers: {
20 'Authorization': `Bearer ${apiKey}`,
21 'Content-Type': 'application/json'
22 },
23 body: JSON.stringify(payload)
24})
25.then(response => response.json())
26.then(data => console.log(data))
27.catch(error => console.error('Error:', error));

Start sending

Ship transactional email in minutes

Create an API key, verify a domain, and send your first message with Piisend.