- Send welcome email 5 minutes after signup
- Trigger a reminder email 24 hours before an event
- Schedule a weekly digest email for the next day at 9am PST
Emails can be scheduled up to 30 days in advance.
1. Schedule using natural language
You can use the various Emailr SDKs to schedule emails. The date can be defined using natural language, such as"in 1 hour", "tomorrow at 9am", or "Friday at 3pm ET".
import { Emailr } from 'emailr';
const emailr = new Emailr('em_xxxxxxxxx');
await emailr.emails.send({
from: 'Acme <[email protected]>',
to: ['[email protected]'],
subject: 'hello world',
html: '<p>it works!</p>',
scheduledAt: 'in 1 min',
});
$emailr = Emailr::client('em_xxxxxxxxx');
$emailr->emails->send([
'from' => 'Acme <[email protected]>',
'to' => ['[email protected]'],
'subject' => 'hello world',
'html' => '<p>it works!</p>',
'scheduled_at' => 'in 1 min'
]);
import emailr
emailr.api_key = "em_xxxxxxxxx"
params: emailr.Emails.SendParams = {
"from": "Acme <[email protected]>",
"to": ["[email protected]"],
"subject": "hello world",
"html": "<p>it works!</p>",
"scheduled_at": "in 1 min"
}
emailr.Emails.send(params)
require "emailr"
Emailr.api_key = "em_xxxxxxxxx"
params = {
"from": "Acme <[email protected]>",
"to": ["[email protected]"],
"subject": "hello world",
"html": "<p>it works!</p>",
"scheduled_at": "in 1 min"
}
Emailr::Emails.send(params)
import (
"fmt"
"github.com/emailr/emailr-go/v3"
)
func main() {
ctx := context.TODO()
client := emailr.NewClient("em_xxxxxxxxx")
params := &emailr.SendEmailRequest{
From: "Acme <[email protected]>",
To: []string{"[email protected]"},
Subject: "hello world",
Html: "<p>it works!</p>",
ScheduledAt: "in 1 min"
}
sent, err := client.Emails.SendWithContext(ctx, params)
if err != nil {
panic(err)
}
fmt.Println(sent.Id)
}
use emailr_rs::types::CreateEmailBaseOptions;
use emailr_rs::{Emailr, Result};
#[tokio::main]
async fn main() -> Result<()> {
let emailr = Emailr::new("em_xxxxxxxxx");
let from = "Acme <[email protected]>";
let to = ["[email protected]"];
let subject = "hello world";
let email = CreateEmailBaseOptions::new(from, to, subject)
.with_html("<p>it works!</p>")
.with_scheduled_at("in 1 min");
let _email = emailr.emails.send(email).await?;
Ok(())
}
import com.emailr.*;
public class Main {
public static void main(String[] args) {
Emailr emailr = new Emailr("em_xxxxxxxxx");
CreateEmailOptions params = CreateEmailOptions.builder()
.from("Acme <[email protected]>")
.to("[email protected]")
.subject("hello world")
.html("<p>it works!</p>")
.scheduledAt("in 1 min")
.build();
CreateEmailResponse data = emailr.emails().send(params);
}
}
using Emailr;
IEmailr emailr = EmailrClient.Create( "em_xxxxxxxxx" ); // Or from DI
var resp = await emailr.EmailSendAsync( new EmailMessage()
{
From = "Acme <[email protected]>",
To = "[email protected]",
Subject = "hello world",
HtmlBody = "<p>it works!</p>",
MomentSchedule = "in 1 min",
} );
Console.WriteLine( "Email Id={0}", resp.Content );
curl -X POST 'https://api.emailr.dev/emails' \
-H 'Authorization: Bearer em_xxxxxxxxx' \
-H 'Content-Type: application/json' \
-d $'{
"from": "Acme <[email protected]>",
"to": ["[email protected]"],
"subject": "hello world",
"html": "<p>it works!</p>",
"scheduled_at": "in 1 min"
}'
2. Schedule using date format
You can also use a date in ISO 8601 format (e.g:2024-08-05T11:52:01.858Z).
import { Emailr } from 'emailr';
const emailr = new Emailr('em_xxxxxxxxx');
const oneMinuteFromNow = new Date(Date.now() + 1000 * 60).toISOString();
await emailr.emails.send({
from: 'Acme <[email protected]>',
to: ['[email protected]'],
subject: 'hello world',
html: '<p>it works!</p>',
scheduledAt: oneMinuteFromNow,
});
$emailr = Emailr::client('em_xxxxxxxxx');
$oneMinuteFromNow = (new DateTime())->modify('+1 minute')->format(DateTime::ISO8601);
$emailr->emails->send([
'from' => 'Acme <[email protected]>',
'to' => ['[email protected]'],
'subject' => 'hello world',
'html' => '<p>it works!</p>',
'scheduled_at' => $oneMinuteFromNow
]);
import emailr
from datetime import datetime, timedelta
emailr.api_key = "em_xxxxxxxxx"
one_minute_from_now = (datetime.now() + timedelta(minutes=1)).isoformat()
params: emailr.Emails.SendParams = {
"from": "Acme <[email protected]>",
"to": ["[email protected]"],
"subject": "hello world",
"html": "<p>it works!</p>",
"scheduled_at": one_minute_from_now
}
emailr.Emails.send(params)
require "emailr"
Emailr.api_key = "em_xxxxxxxxx"
one_minute_from_now = (Time.now + 1 * 60).strftime("%Y-%m-%dT%H:%M:%S.%L%z")
params = {
"from": "Acme <[email protected]>",
"to": ["[email protected]"],
"subject": "hello world",
"html": "<p>it works!</p>",
"scheduled_at": one_minute_from_now
}
Emailr::Emails.send(params)
import (
"fmt"
"github.com/emailr/emailr-go/v3"
)
func main() {
ctx := context.TODO()
client := emailr.NewClient("em_xxxxxxxxx")
oneMinuteFromNow := time.Now().Add(time.Minute * time.Duration(1))
oneMinuteFromNowISO := oneMinuteFromNow.Format("2006-01-02T15:04:05-0700")
params := &emailr.SendEmailRequest{
From: "Acme <[email protected]>",
To: []string{"[email protected]"},
Subject: "hello world",
Html: "<p>it works!</p>",
ScheduledAt: oneMinuteFromNowISO
}
sent, err := client.Emails.SendWithContext(ctx, params)
if err != nil {
panic(err)
}
fmt.Println(sent.Id)
}
use chrono::{Local, TimeDelta};
use emailr_rs::types::CreateEmailBaseOptions;
use emailr_rs::{Emailr, Result};
#[tokio::main]
async fn main() -> Result<()> {
let emailr = Emailr::new("em_xxxxxxxxx");
let from = "Acme <[email protected]>";
let to = ["[email protected]"];
let subject = "hello world";
let one_minute_from_now = Local::now()
.checked_add_signed(TimeDelta::minutes(1))
.unwrap()
.to_rfc3339();
let email = CreateEmailBaseOptions::new(from, to, subject)
.with_html("<p>it works!</p>")
.with_scheduled_at(&one_minute_from_now);
let _email = emailr.emails.send(email).await?;
Ok(())
}
import com.emailr.*;
public class Main {
public static void main(String[] args) {
Emailr emailr = new Emailr("em_xxxxxxxxx");
String oneMinuteFromNow = Instant
.now()
.plus(1, ChronoUnit.MINUTES)
.toString();
CreateEmailOptions params = CreateEmailOptions.builder()
.from("Acme <[email protected]>")
.to("[email protected]")
.subject("hello world")
.html("<p>it works!</p>")
.scheduledAt(oneMinuteFromNow)
.build();
CreateEmailResponse data = emailr.emails().send(params);
}
}
using Emailr;
IEmailr emailr = EmailrClient.Create( "em_xxxxxxxxx" ); // Or from DI
var resp = await emailr.EmailSendAsync( new EmailMessage()
{
From = "Acme <[email protected]>",
To = "[email protected]",
Subject = "hello world",
HtmlBody = "<p>it works!</p>",
MomentSchedule = DateTime.UtcNow.AddMinutes( 1 ),
} );
Console.WriteLine( "Email Id={0}", resp.Content );
curl -X POST 'https://api.emailr.dev/emails' \
-H 'Authorization: Bearer em_xxxxxxxxx' \
-H 'Content-Type: application/json' \
-d $'{
"from": "Acme <[email protected]>",
"to": ["[email protected]"],
"subject": "hello world",
"html": "<p>it works!</p>",
"scheduled_at": "2024-08-20T11:52:01.858Z"
}'
View a scheduled email
Once you schedule an email, you can see the scheduled time in the Emailr dashboard.Reschedule an email
After scheduling an email, you might need to update the scheduled time. You can do so with the following method:emailr.emails.update({
id: '49a3999c-0ce1-4ea6-ab68-afcd6dc2e794',
scheduledAt: 'in 1 min',
});
$emailr->emails->update('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794', [
'scheduled_at' => 'in 1 min'
]);
update_params: emailr.Emails.UpdateParams = {
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
"scheduled_at": "in 1 min"
}
emailr.Emails.update(params=update_params)
update_params = {
"email_id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
"scheduled_at": "in 1 min"
}
updated_email = Emailr::Emails.update(update_params)
updateParams := &emailr.UpdateEmailRequest{
Id: "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
ScheduledAt: "in 1 min",
}
updatedEmail, err := client.Emails.Update(updateParams)
if err != nil {
panic(err)
}
fmt.Printf("%v\n", updatedEmail)
let update = UpdateEmailOptions::new()
.with_scheduled_at("in 1 min");
let _email = emailr
.emails
.update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", update)
.await?;
UpdateEmailOptions updateParams = UpdateEmailOptions.builder()
.scheduledAt("in 1 min")
.build();
UpdateEmailResponse data = emailr.emails().update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", updateParams);
using Emailr;
IEmailr emailr = EmailrClient.Create( "em_xxxxxxxxx" ); // Or from DI
await emailr.EmailRescheduleAsync(
new Guid( "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794" ),
"in 1 min"
);
curl -X PATCH 'https://api.emailr.dev/emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794' \
-H 'Authorization: Bearer em_xxxxxxxxx' \
-H 'Content-Type: application/json' \
-d $'{
"scheduled_at": "in 1 min"
}'
Cancel a scheduled email
Once an email is canceled, it cannot be rescheduled.
emailr.emails.cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
$emailr->emails->cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
emailr.Emails.cancel(email_id="49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
Emailr::Emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
canceled, err := client.Emails.Cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
if err != nil {
panic(err)
}
fmt.Println(canceled.Id)
let _canceled = emailr
.emails
.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
.await?;
CancelEmailResponse canceled = emailr
.emails()
.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794");
using Emailr;
IEmailr emailr = EmailrClient.Create( "em_xxxxxxxxx" ); // Or from DI
await emailr.EmailCancelAsync( new Guid( "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794" ) );
curl -X POST 'https://api.emailr.dev/emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794/cancel' \
-H 'Authorization: Bearer em_xxxxxxxxx' \
-H 'Content-Type: application/json'