βοΈ Send Emails
NotificationAPI makes it easy to send emails without third parties like Twilio. Hereβs how.
Install the SDK:
npm install notificationapi-node-server-sdk pip install notificationapi_python_server_sdk composer require notificationapi/notificationapi-php-server-sdk go get github.com/notificationapi-com/notificationapi-go-server-sdk dotnet add package NotificationAPI --version 0.5.0 Add the following dependency to your pom.xml file:
<dependencies>
<dependency>
<groupId>com.notificationapi</groupId>
<artifactId>notificationapi-java-server-sdk</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
</dependencies> Add the NotificationAPI class to your application - see the full Ruby implementation.
Now, send an email notification from your backend:
TIP
Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the values from the
code sample in your NotificationAPI dashboard. These values can also be found
in the Environments section of the dashboard.
import notificationapi from 'notificationapi-node-server-sdk';
// Initialize (default US region)
// For CA region: add 'https://api.ca.notificationapi.com' after CLIENT_SECRET
// For EU region: add 'https://api.eu.notificationapi.com' after CLIENT_SECRET
notificationapi.init('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// Send email notification
notificationapi.send({
type: 'welcome_email',
to: {
id: 'user123',
email: 'user@example.com' // Required for email notifications
},
email: {
subject: 'Welcome to Acme Corp',
html: '<h1>Welcome!</h1><p>Thanks for joining Acme Corp.</p>',
senderName: 'Acme Team',
senderEmail: 'hello@acme.com'
}
}); import asyncio
from notificationapi_python_server_sdk import notificationapi
# Initialize (default US region)
notificationapi.init("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
async def send_email():
await notificationapi.send({
"type": "welcome_email",
"to": {
"id": "user123",
"email": "user@example.com" # Required for email notifications
},
"email": {
"subject": "Welcome to Acme Corp",
"html": "<h1>Welcome!</h1><p>Thanks for joining Acme Corp.</p>",
"senderName": "Acme Team",
"senderEmail": "hello@acme.com"
}
})
# Run the async function
asyncio.run(send_email()) use NotificationAPI\NotificationAPI;
// Initialize
$notificationapi = new NotificationAPI('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// Send email notification
$notificationapi->send([
"type" => "welcome_email",
"to" => [
"id" => "user123",
"email" => "user@example.com" // Required for email notifications
],
"email" => [
"subject" => "Welcome to Acme Corp",
"html" => "<h1>Welcome!</h1><p>Thanks for joining Acme Corp.</p>",
"senderName" => "Acme Team",
"senderEmail" => "hello@acme.com"
]
]); package main
import (
notificationapi "github.com/notificationapi-com/notificationapi-go-server-sdk"
)
func main() {
// Initialize
notificationapi.Init("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", "https://api.notificationapi.com")
// Prepare parameters
parameters := make(map[string]interface{})
parameters["firstName"] = "John"
parameters["companyName"] = "Acme Corp"
// Send email notification
notificationapi.Send(
notificationapi.SendRequest{
Type: "welcome_email",
To: notificationapi.User{
Id: "user123",
Email: "user@example.com", // Required for email notifications
},
Email: map[string]interface{}{
"subject": "Welcome to Acme Corp",
"html": "<h1>Welcome!</h1><p>Thanks for joining Acme Corp.</p>",
"senderName": "Acme Team",
"senderEmail":"hello@acme.com",
},
},
)
} using NotificationApi.Server;
using NotificationApi.Server.Models;
var notificationApi = new NotificationApiServer("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
notification = new SendNotificationData
Type = "welcome_email",
To = new User
{
Id = "user123",
Email = "user@example.com",
Number = "+15005550006" // Replace with your phone number, use format [+][country code][area code][local number]
},
Email = new Dictionary<string, object>
{
{ "subject", "Welcome to Acme Corp" },
{ "html", "<h1>Welcome!</h1><p>Thanks for joining Acme Corp.</p>" },
{ "senderName", "Acme Team" },
{ "senderEmail", "hello@acme.com" }
}
it notificationApi.Send(notification); package com.example;
import com.notificationapi.NotificationApi;
import com.notificationapi.model.*;
public class Example {
public static void main(String[] args) {
NotificationApi api = new NotificationApi(
"YOUR_CLIENT_ID",
"YOUR_CLIENT_SECRET"
);
// Create user
User user = new User("user123")
.setEmail("user@example.com")
.setNumber("+15005550006"); // Replace with your phone number, use format [+][country code][area code][local number];
// Create and send notification request
NotificationRequest request = new NotificationRequest("account_update_api", user)
.setEmail(new EmailOptions()
.setSubject("Welcome to Acme Corp")
.setHtml("<h1>Welcome!</h1><p>Thanks for joining Acme Corp.</p>"),
.setSenderName("Acme Team")
.setSenderEmail("hello@acme.com")
);
System.out.println("Sending notification request...");
String response = api.send(request);
System.out.println("Response: " + response);
}
} # Initialize
notificationapi = NotificationAPI.new("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
# Send email notification
notificationapi.send({
type: 'welcome_email',
to: {
id: 'user123',
email: 'user@example.com' # Required for email notifications
},
email: {
subject: 'Welcome to Acme Corp',
html: '<h1>Welcome!</h1><p>Thanks for joining Acme Corp.</p>',
senderName: 'Acme Team',
senderEmail: 'hello@acme.com'
}
}) Youβre All Set!
π Congrats! Youβre now sending email notifications!
For more advanced features like attachments, CC/BCC, and custom templates, check out our Email Channel documentation.