Send Email

Learn how to send messages with Unipile

Feature available for : Google, Microsoft, IMAP

Send an email

Use the POST emails Method or use the appropriate SDK Method, to send an email to every recipient.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'cc=[
	{
		"display_name": "Jane Doe",
		"identifier": "[email protected]"
	}
]' \
const email: SendEmailInput = {
  account_id: "kzAxdybMQ7ipVxK1U6kwZw",
  to: [
    {
      display_name: "John Doe",
      identifier: "[email protected]",
    },
  ],
  cc: [
    {
      display_name: "Jane Doe",
      identifier: "[email protected]",
    },
  ],
  subject: "Hello from Unipile",
  body: "Hello, this is a test email from Unipile",
}

await client.email.send(email)

Send attachments

You can provide an additional attachment to the request body to send attachments along your email.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'attachments=@C:\Documents\cute_dog.png'
const filePath = "C:\\Documents\\cute_dog.png";
const buffer = await fs.promises.readFile(filePath);

const attachment: [string, Buffer] = [ path.basename(filePath), buffer ];

const email: SendEmailInput = {
  account_id: "kzAxdybMQ7ipVxK1U6kwZw",
  to: [
    {
      display_name: "John Doe",
      identifier: "[email protected]",
    },
  ],
  subject: "Hello from Unipile",
  body: "Hello, this is a test email from Unipile",
  attachments: [ attachment ],
}

await client.email.send(email)

Send with custom headers

You can set additional custom headers using the "X-" syntax.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'cc=[
	{
		"display_name": "Jane Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'custom_headers=[
    {
      "name": "X-My-Custom-Header",
      "value": "Example value"
    }
const email: SendEmailInput = {
  account_id: "kzAxdybMQ7ipVxK1U6kwZw",
  to: [
    {
      display_name: "John Doe",
      identifier: "[email protected]",
    },
  ],
  cc: [
    {
      display_name: "Jane Doe",
      identifier: "[email protected]",
    },
  ],
  subject: "Hello from Unipile",
  body: "Hello, this is a test email from Unipile",
  custom_headers: [
    {
      name: "X-My-Custom-Header",
      value: "Example value",
    }
  ]
}

await client.email.send(email)