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

# How to send emails with Nodemailer and AutoSend SMTP

> Send transactional emails from Node.js applications using Nodemailer with AutoSend SMTP.

export const APP_PATHS = {
  home: '/',
  quickstart: '/quickstart',
  domainConfiguration: '/domain',
  apiReference: '/api-reference',
  sendEmail: '/api-reference/mails/send',
  bulkSendEmail: '/api-reference/mails/bulk',
  upsertContactApiRef: '/api-reference/contacts/upsert-contact',
  transactional: '/transactional-emails',
  emailActivity: '/transactional-emails/email-activity',
  emailTemplates: '/transactional-emails/email-templates',
  sendingEmail: '/quickstart/email-using-api',
  transactionalTroubleshooting: '/transactional-emails/troubleshooting',
  marketing: '/marketing-emails',
  campaigns: '/marketing-emails/campaigns',
  contacts: '/marketing-emails/contacts',
  contactsIntroduction: '/marketing-emails/contacts/introduction',
  contactsImportCsv: '/marketing-emails/contacts/import-csv',
  contactsLists: '/marketing-emails/contacts/lists',
  contactsSegments: '/marketing-emails/contacts/segments',
  contactsCustomFields: '/marketing-emails/contacts/contact-properties',
  contactsContactProperties: '/marketing-emails/contacts/contact-properties',
  createContactPropertyApiRef: '/api-reference/contact-properties/create',
  listContactPropertiesApiRef: '/api-reference/contact-properties/list',
  getContactPropertyApiRef: '/api-reference/contact-properties/get-by-name',
  deleteContactPropertyApiRef: '/api-reference/contact-properties/delete',
  sender: '/marketing-emails/sender',
  unsubscribeGroups: '/others/unsubscribe-groups',
  webhookIntroduction: '/others/webhooks/introduction',
  webhookEventType: '/others/webhooks/event-type',
  webhookRetries: '/others/webhooks/retries',
  webhookVerifyRequests: '/others/webhooks/verify-requests',
  dynamicTemplates: '/dynamic-templates',
  guides: '/guides',
  sitemap: '/sitemap.xml',
  team: '/others/team',
  automations: '/automations',
  events: '/automations/events',
  sendEventApi: '/api-reference/events/send-event',
  smtpIntroduction: '/quickstart/smtp',
  betterAuth: '/guides/better-auth',
  convexGuide: '/guides/convex',
  templateVariables: '/transactional-emails/variables',
  suppressions: '/others/suppressions',
  rateLimit: '/api-reference/rate-limit',
  nodejsSdk: '/sdk/nodejs',
  smtpIntegrationGuides: '/guides/smtp',
  apiKeys: '/api-keys',
  encryptedPayloads: '/others/encrypted-payloads',
  apiReferenceIntroduction: '/api-reference/introduction',
  lovableGuide: '/ai/integrations/lovable',
  aiIntroduction: '/ai/introduction',
  aiSkills: '/ai/skills',
  aiMcpServer: '/ai/mcp-server',
  aiLovable: '/ai/integrations/lovable',
  aiBolt: '/ai/integrations/bolt',
  aiV0: '/ai/integrations/v0',
  aiReplit: '/ai/integrations/replit',
  mcpClaude: '/ai/mcp-clients/claude',
  mcpCursor: '/ai/mcp-clients/cursor',
  mcpCopilot: '/ai/mcp-clients/copilot',
  mcpWindsurf: '/ai/mcp-clients/windsurf',
  mcpCodex: '/ai/mcp-clients/codex',
  mcpAntigravity: '/ai/mcp-clients/antigravity',
  mcpChatgpt: '/ai/mcp-clients/chatgpt',
  mcpRaycast: '/ai/mcp-clients/raycast',
  domainWarmup: '/marketing-emails/domain-warmup',
  projects: '/projects',
  createAutomationApi: '/api-reference/automations/create-automation',
  migrationSendgrid: '/migration/sendgrid',
  migrationResend: '/migration/resend',
  auth0CustomAction: '/guides/auth0-custom-action',
  accountBilling: '/others/account/billing',
  accountUsage: '/others/account/usage',
  inboundIntroduction: '/inbound/introduction',
  listInboundMessagesApi: '/api-reference/inbound-emails/list-messages',
  getInboundMessageApi: '/api-reference/inbound-emails/get-message',
  downloadInboundAttachmentApi: '/api-reference/inbound-emails/download-attachment',
  replyToInboundMessageApi: '/api-reference/inbound-emails/reply-to-message',
  wikiDailySendingLimit: '/wiki/daily-sending-limit'
};

export const AUTOSEND_PATHS = {
  dashboard: 'https://autosend.com/dashboard',
  apiKey: 'https://autosend.com/account/api-key',
  faqs: 'https://autosend.com/faq',
  marketingEmails: 'https://autosend.com/marketing-emails',
  webhooks: 'https://autosend.com/webhooks',
  composeByAutoSend: 'https://autosend.com/compose',
  emailActivity: 'https://autosend.com/email-activities',
  team: 'https://autosend.com/settings/team',
  pricing: 'https://autosend.com/pricing',
  verifyEmail: 'https://autosend.com/compose/email-builder?template=verify-email',
  welcomeEmail: 'https://autosend.com/compose/email-builder?template=welcome-email',
  productUpdate: 'https://autosend.com/compose/email-builder?template=product-update',
  newsletter: 'https://autosend.com/compose/email-builder?template=newsletter',
  automations: 'https://autosend.com/automations',
  globalSuppressions: 'https://autosend.com/suppressions/global',
  signup: 'https://autosend.com/signup',
  domains: 'https://autosend.com/settings/domains',
  smtpKey: 'https://autosend.com/settings/smtp',
  logoKit: 'https://asend.email/logo',
  contactsPage: 'https://autosend.com/contacts/list-and-segments',
  accountBilling: 'https://autosend.com/account/billing',
  accountUsage: 'https://autosend.com/account/usage',
  terms: 'https://autosend.com/legal/terms',
  inbound: 'https://autosend.com/email-activities/inbound'
};

<Frame>
  <img src="https://mintcdn.com/autosend-13920f5c/hmgNOatbvpHf3GrN/images/smtp/autosendxnodemailer.jpg?fit=max&auto=format&n=hmgNOatbvpHf3GrN&q=85&s=6fb2476ac6262a4e70a8e7c701c53057" alt="AutoSend x Nodemailer" width="1800" height="600" data-path="images/smtp/autosendxnodemailer.jpg" />
</Frame>

[Nodemailer](https://nodemailer.com/) is the most popular email sending library for Node.js. By integrating Nodemailer with AutoSend SMTP, you can send transactional emails from your Node.js applications with reliable delivery, full tracking, and detailed analytics.

## Prerequisites

<CardGroup cols={2}>
  <Card title="Verified Domain" href="https://autosend.com/settings/domains">
    Make sure you have a verified domain added in AutoSend to send emails from.
  </Card>

  <Card title="SMTP Key" href={AUTOSEND_PATHS.smtpKey}>
    Create a project-specific SMTP key from the SMTP tab in Project Settings.
  </Card>
</CardGroup>

## Configuration

<Steps>
  <Step title="Install Nodemailer" titleSize="h3">
    Install the Nodemailer package using your preferred package manager:

    <CodeGroup>
      ```bash npm theme={null}
      npm install nodemailer
      ```

      ```bash yarn theme={null}
      yarn add nodemailer
      ```

      ```bash pnpm theme={null}
      pnpm add nodemailer
      ```

      ```bash bun theme={null}
      bun add nodemailer
      ```
    </CodeGroup>
  </Step>

  <Step title="Create the SMTP Transporter" titleSize="h3">
    Configure the Nodemailer transporter with your AutoSend SMTP credentials:

    ```javascript theme={null}
    import nodemailer from 'nodemailer';

    const transporter = nodemailer.createTransport({
      host: 'smtp.autosend.com',
      port: 465,
      secure: true,
      auth: {
        user: 'autosend',
        pass: 'AS_xxx', // Your AutoSend SMTP key
      },
    });
    ```

    | Field        | Value                                     |
    | ------------ | ----------------------------------------- |
    | **Host**     | `smtp.autosend.com`                       |
    | **Port**     | `465` (recommended) or `587`              |
    | **Username** | `autosend`                                |
    | **Password** | Your AutoSend SMTP key (AS\_xxx)          |
    | **Secure**   | `true` for port 465, `false` for port 587 |

    <Note>
      The SMTP password is no longer your API key. Create a project-specific SMTP key from the SMTP tab in <a href={AUTOSEND_PATHS.smtpKey} target="_blank" rel="noopener noreferrer">Project Settings</a>.
    </Note>
  </Step>

  <Step title="Send an Email" titleSize="h3">
    Use the `sendMail` method to send your email:

    ```javascript theme={null}
    const info = await transporter.sendMail({
      from: 'sender@yourdomain.com',
      to: 'recipient@example.com',
      subject: 'Hello from AutoSend',
      html: '<h1>Welcome!</h1><p>This email was sent via Nodemailer and AutoSend SMTP.</p>',
    });

    console.log('Message sent:', info.messageId);
    ```

    <Note>
      The `from` address must use a domain that is verified in AutoSend. For example, if you verified `yourdomain.com`, use an address like `sender@yourdomain.com`.
    </Note>
  </Step>

  <Step title="Verify Delivery" titleSize="h3">
    Check the <a href={AUTOSEND_PATHS.emailActivity} target="_blank" rel="noopener noreferrer">Email Activity</a> dashboard to verify your email was sent successfully. You'll see delivery status, opens, clicks, and other engagement metrics.
  </Step>
</Steps>

***

## Complete Examples

<CodeGroup>
  ```javascript JavaScript (ES Modules) expandable theme={null}
  import nodemailer from 'nodemailer';

  const transporter = nodemailer.createTransport({
  	host: 'smtp.autosend.com',
  	port: 465,
  	secure: true,
  	auth: {
  		user: 'autosend',
  		pass: 'AS_xxx',
  	},
  });

  async function sendEmail() {
  	const info = await transporter.sendMail({
  		from: 'sender@yourdomain.com',
  		to: 'recipient@example.com',
  		subject: 'Hello from AutoSend',
  		html: '<h1>Welcome!</h1><p>This email was sent via Nodemailer and AutoSend SMTP.</p>',
  	});

  	console.log('Message sent:', info.messageId);
  }

  sendEmail().catch(console.error);
  ```

  ```javascript JavaScript (CommonJS) expandable theme={null}
  const nodemailer = require('nodemailer');

  const transporter = nodemailer.createTransport({
  	host: 'smtp.autosend.com',
  	port: 465,
  	secure: true,
  	auth: {
  		user: 'autosend',
  		pass: 'AS_xxx',
  	},
  });

  async function sendEmail() {
  	const info = await transporter.sendMail({
  		from: 'sender@yourdomain.com',
  		to: 'recipient@example.com',
  		subject: 'Hello from AutoSend',
  		html: '<h1>Welcome!</h1><p>This email was sent via Nodemailer and AutoSend SMTP.</p>',
  	});

  	console.log('Message sent:', info.messageId);
  }

  sendEmail().catch(console.error);
  ```

  ```typescript TypeScript expandable theme={null}
  import nodemailer from 'nodemailer';
  import type { Transporter } from 'nodemailer';

  const transporter: Transporter = nodemailer.createTransport({
  	host: 'smtp.autosend.com',
  	port: 465,
  	secure: true,
  	auth: {
  		user: 'autosend',
  		pass: 'AS_xxx',
  	},
  });

  async function sendEmail(): Promise<void> {
  	const info = await transporter.sendMail({
  		from: 'sender@yourdomain.com',
  		to: 'recipient@example.com',
  		subject: 'Hello from AutoSend',
  		html: '<h1>Welcome!</h1><p>This email was sent via Nodemailer and AutoSend SMTP.</p>',
  	});

  	console.log('Message sent:', info.messageId);
  }

  sendEmail().catch(console.error);
  ```
</CodeGroup>

***

## Advanced Usage

### Sending with Attachments

```javascript theme={null}
await transporter.sendMail({
	from: 'sender@yourdomain.com',
	to: 'recipient@example.com',
	subject: 'Email with Attachment',
	html: '<p>Please find the attached file.</p>',
	attachments: [
		{
			filename: 'document.pdf',
			path: './files/document.pdf',
		},
		{
			filename: 'image.png',
			content: imageBuffer,
		},
	],
});
```

### Sending to Multiple Recipients

```javascript theme={null}
await transporter.sendMail({
	from: 'sender@yourdomain.com',
	to: 'recipient1@example.com, recipient2@example.com',
	cc: 'cc@example.com',
	bcc: 'bcc@example.com',
	subject: 'Hello Everyone',
	html: '<p>This email is sent to multiple recipients.</p>',
});
```

### Plain Text and HTML

```javascript theme={null}
await transporter.sendMail({
	from: 'sender@yourdomain.com',
	to: 'recipient@example.com',
	subject: 'Hello from AutoSend',
	text: 'This is the plain text version of the email.',
	html: '<h1>Hello!</h1><p>This is the HTML version of the email.</p>',
});
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Emails not being sent">
    * Verify your SMTP credentials are correct - Check that your sender email domain is verified in
      AutoSend - Ensure the `from` address matches a verified domain - Check your application logs for
      SMTP connection errors
  </Accordion>

  <Accordion title="Authentication failed">
    * Double-check your SMTP key is correct - Ensure you're using `autosend` as the username - Verify
      your SMTP key is active in the <a href={AUTOSEND_PATHS.smtpKey} target="_blank" rel="noopener noreferrer">SMTP Settings</a> - Make sure there are no extra spaces in the
      credentials
  </Accordion>

  <Accordion title="Connection errors">
    * Verify the hostname is `smtp.autosend.com` - Try using port `587` with `secure: false` if port
      `465` fails - Check if your network or firewall blocks outbound SMTP connections - Test
      connectivity: `telnet smtp.autosend.com 465`
  </Accordion>

  <Accordion title="Emails going to spam">
    * Ensure your domain has proper DNS records (SPF, DKIM, DMARC) - Use a professional sender name
      and address - Check your domain reputation in AutoSend - Avoid spam trigger words in your email
      content
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Verify Your Domain" icon="https://mintcdn.com/autosend-13920f5c/nx_wYfWx3qeZwg1C/icons/domain.svg?fit=max&auto=format&n=nx_wYfWx3qeZwg1C&q=85&s=9393f9f9b0f7029e6ba8acf2bc09d864" href="/domain" width="24" height="24" data-path="icons/domain.svg">
    Set up SPF, DKIM, and DMARC for better deliverability
  </Card>

  <Card title="Email Activity" icon="https://mintcdn.com/autosend-13920f5c/nx_wYfWx3qeZwg1C/icons/email-activity.svg?fit=max&auto=format&n=nx_wYfWx3qeZwg1C&q=85&s=2ecad7369f217ee7d03c3d8dfdd36d22" href="/transactional-emails/email-activity" width="24" height="24" data-path="icons/email-activity.svg">
    Monitor your email delivery and engagement
  </Card>

  <Card title="Webhooks" icon="https://mintcdn.com/autosend-13920f5c/nx_wYfWx3qeZwg1C/icons/webhook.svg?fit=max&auto=format&n=nx_wYfWx3qeZwg1C&q=85&s=14ad6675c71731ac04f786559a813ee1" href="/others/webhooks/introduction" width="24" height="24" data-path="icons/webhook.svg">
    Set up webhooks to track email events in real-time
  </Card>

  <Card title="SMTP Introduction" icon="https://mintcdn.com/autosend-13920f5c/nx_wYfWx3qeZwg1C/icons/smtp.svg?fit=max&auto=format&n=nx_wYfWx3qeZwg1C&q=85&s=d1993edda392d54c3f704a9a4bb04442" href="/quickstart/smtp" width="24" height="24" data-path="icons/smtp.svg">
    Learn more about AutoSend SMTP configuration
  </Card>
</CardGroup>
