> ## Documentation Index
> Fetch the complete documentation index at: https://docs.senderr.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Sending an email via Senderr using n8n

> Learn how to use Senderr templates with n8n workflows for automated email sending

# Sending an email via Senderr using n8n

n8n is a powerful workflow automation tool that allows you to create custom integrations between different services. This guide shows you how to integrate Senderr email templates into your n8n workflows.

## Prerequisites

Before you begin, make sure you have:

* An active n8n instance (cloud or self-hosted)
* A Senderr account with templates in your library
* A Senderr API key ([generate one here](https://senderr.dev/dashboard/settings))
* A Resend account for sending emails ([sign up here](https://resend.com))

## Basic Workflow Setup

### Step 1: Create a New Workflow

1. Open your n8n instance
2. Create a new workflow
3. Add a trigger node (e.g., Manual Trigger, Webhook, or Schedule)

### Step 2: Fetch Template List

Add an HTTP Request node to get your available templates:

```json theme={null}
{
  "method": "GET",
  "url": "https://senderr.dev/api/v1/library",
  "headers": {
    "Authorization": "Bearer {{ $env.SENDERR_API_KEY }}",
    "Content-Type": "application/json"
  }
}
```

**Environment Variable Setup:**

* In n8n, go to Settings → Environment Variables
* Add `SENDERR_API_KEY` with your API key value

### Step 3: Get Template Schema

To understand what variables a template needs, fetch its schema:

```json theme={null}
{
  "method": "GET",
  "url": "https://senderr.dev/api/v1/templates/{{ $json.templates[0].id }}/schema",
  "headers": {
    "Authorization": "Bearer {{ $env.SENDERR_API_KEY }}",
    "Content-Type": "application/json"
  }
}
```

### Step 4: Render Template with Variables

Add another HTTP Request node to render the template with your data:

```json theme={null}
{
  "method": "POST",
  "url": "https://senderr.dev/api/v1/templates/{{ $json.template_id }}/render",
  "headers": {
    "Authorization": "Bearer {{ $env.SENDERR_API_KEY }}",
    "Content-Type": "application/json"
  },
  "body": {
    "variables": {
      "name": "{{ $json.customer_name }}",
      "company": "{{ $json.company_name }}",
      "email": "{{ $json.customer_email }}"
    },
    "format": "html"
  }
}
```

### Step 5: Send Email with Resend

Finally, add a Resend node to send the rendered template:

1. Add the Resend node from the node library
2. Configure it with your Resend API key
3. Set the email parameters:

```json theme={null}
{
  "from": "noreply@yourcompany.com",
  "to": "{{ $json.customer_email }}",
  "subject": "{{ $json.email_subject }}",
  "html": "{{ $node['HTTP Request 2'].json.html }}"
}
```

## Advanced Example: Welcome Email Sequence

Here's a complete workflow that sends a personalized welcome email when a new user signs up:

### Workflow Structure

1. **Webhook Trigger** - Receives new user data
2. **Set Variables** - Prepares template variables
3. **Get Template** - Fetches the welcome email template
4. **Render Template** - Populates it with user data
5. **Send Email** - Delivers via Resend
6. **Log Activity** - Records the action

### HTTP Request Node Configuration

**Node 1: Get Welcome Template**

```json theme={null}
{
  "method": "GET",
  "url": "https://senderr.dev/api/v1/library",
  "headers": {
    "Authorization": "Bearer {{ $env.SENDERR_API_KEY }}"
  },
  "qs": {
    "filter": "welcome"
  }
}
```

**Node 2: Render Template**

```json theme={null}
{
  "method": "POST",
  "url": "https://senderr.dev/api/v1/templates/{{ $json.templates[0].id }}/render",
  "headers": {
    "Authorization": "Bearer {{ $env.SENDERR_API_KEY }}",
    "Content-Type": "application/json"
  },
  "body": {
    "variables": {
      "firstName": "{{ $node['Webhook'].json.body.first_name }}",
      "lastName": "{{ $node['Webhook'].json.body.last_name }}",
      "email": "{{ $node['Webhook'].json.body.email }}",
      "companyName": "Your Company",
      "dashboardUrl": "https://yourapp.com/dashboard",
      "supportEmail": "support@yourcompany.com"
    },
    "format": "html"
  }
}
```

## Error Handling

Add error handling to your workflow:

### Check API Response

Add an IF node after each HTTP request to check for success:

```javascript theme={null}
// Expression for checking Senderr API response
{{ $json.success === true }}
```

### Fallback Template

If the template fetch fails, use a fallback:

```json theme={null}
{
  "html": "<h1>Welcome!</h1><p>Thanks for joining us, {{ $json.firstName }}!</p>",
  "subject": "Welcome to Our Platform"
}
```

## Dynamic Template Selection

You can dynamically choose templates based on user data:

```javascript theme={null}
// Expression to select template based on user type
{{ $node['Webhook'].json.body.user_type === 'premium' ? 'premium-welcome' : 'standard-welcome' }}
```

## Best Practices

### 1. Environment Variables

Store all sensitive data in environment variables:

* `SENDERR_API_KEY`
* `RESEND_API_KEY`
* Template IDs for different email types

### 2. Error Handling

Always include error handling for:

* API request failures
* Missing template variables
* Email delivery failures

### 3. Logging

Add logging nodes to track:

* Template rendering success/failure
* Email delivery status
* User interaction data

### 4. Rate Limiting

Be mindful of API rate limits:

* Senderr: Based on your subscription plan
* Resend: Check your plan limits

## Common Use Cases

### Customer Onboarding

* Welcome emails
* Setup instructions
* Feature introductions

### E-commerce

* Order confirmations
* Shipping notifications
* Product recommendations

### Marketing Automation

* Newsletter campaigns
* Promotional emails
* Re-engagement sequences

### Transactional Emails

* Password resets
* Account notifications
* Billing updates

## Troubleshooting

### Authentication Issues

* Verify your API key is correct
* Check that environment variables are set
* Ensure API key has proper permissions

### Template Not Found

* Check template ID is correct
* Verify template exists in your library
* Ensure template is published

### Variable Errors

* Compare your variables with the template schema
* Check for required vs optional fields
* Validate variable data types

### Email Delivery Issues

* Verify Resend API key and domain setup
* Check email format and recipient validity
* Review Resend delivery logs

## Next Steps

* [Explore more templates](https://senderr.dev/templates)
* [Check out Python integration](/guides/integrations/python)
* [Learn about TypeScript integration](/guides/integrations/typescript)
* [Visit the API reference](/api-reference/introduction)

Need help? Contact [support@senderr.dev](mailto:support@senderr.dev)
