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

# SMTP Integration

> Learn how to send emails using SMTP with Unosend. Connect your existing tools like Laravel, WordPress, Supabase, Django, and more.

Send emails using SMTP without the need for any external libraries or dependencies. Connect seamlessly with your existing tools and frameworks.

## SMTP Credentials

Use these credentials to connect any SMTP-compatible application to Unosend:

<Frame>
  <img src="https://mintcdn.com/unosend/5F-pmOYUAiKBQt9S/images/smtp.png?fit=max&auto=format&n=5F-pmOYUAiKBQt9S&q=85&s=ebe5e8624d6917ff48beeb2f58f3dc85" alt="Smtp" width="1385" height="923" data-path="images/smtp.png" />
</Frame>

<Tip>
  You can find your SMTP credentials in [Settings → SMTP](/settings?tab=smtp) or create a new API key in [API Keys](/api-keys).
</Tip>

## Connection Security

<CardGroup cols={2}>
  <Card title="STARTTLS (Recommended)" icon="lock">
    Upgrades the connection to secure. Works with most email clients and services like Supabase.

    `Port 587`
  </Card>

  <Card title="SMTPS (Implicit TLS)" icon="shield-check">
    Immediately connects via SSL/TLS. Use when your client requires implicit TLS.

    `Port 465`
  </Card>
</CardGroup>

## Quick Start Examples

<CodeGroup>
  ```javascript Nodemailer (Node.js) theme={null}
  import nodemailer from 'nodemailer';

  const transporter = nodemailer.createTransport({
    host: 'smtp.unosend.co',
    port: 587,
    secure: false, // true for 465, false for 587
    auth: {
      user: 'emailapikey',
      pass: 'un_your_api_key', // Your API key
    },
  });

  async function sendEmail() {
    const info = await transporter.sendMail({
      from: 'hello@yourdomain.com',
      to: 'user@example.com',
      subject: 'Hello from Unosend!',
      html: '<h1>It works!</h1>',
    });

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

  sendEmail();
  ```

  ```python Python (smtplib) theme={null}
  import smtplib
  from email.mime.text import MIMEText
  from email.mime.multipart import MIMEMultipart

  smtp_host = "smtp.unosend.co"
  smtp_port = 587
  smtp_user = "emailapikey"
  smtp_pass = "un_your_api_key"  # Your API key

  msg = MIMEMultipart()
  msg['From'] = 'hello@yourdomain.com'
  msg['To'] = 'user@example.com'
  msg['Subject'] = 'Hello from Unosend!'

  body = '<h1>It works!</h1>'
  msg.attach(MIMEText(body, 'html'))

  with smtplib.SMTP(smtp_host, smtp_port) as server:
      server.starttls()
      server.login(smtp_user, smtp_pass)
      server.send_message(msg)
      print('Email sent successfully!')
  ```

  ```env Laravel (.env) theme={null}
  MAIL_MAILER=smtp
  MAIL_HOST=smtp.unosend.co
  MAIL_PORT=587
  MAIL_USERNAME=emailapikey
  MAIL_PASSWORD=un_your_api_key
  MAIL_ENCRYPTION=tls
  MAIL_FROM_ADDRESS=hello@yourdomain.com
  MAIL_FROM_NAME="${APP_NAME}"
  ```

  ```python Django (settings.py) theme={null}
  # Email configuration
  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  EMAIL_HOST = 'smtp.unosend.co'
  EMAIL_PORT = 587
  EMAIL_USE_TLS = True
  EMAIL_HOST_USER = 'emailapikey'
  EMAIL_HOST_PASSWORD = 'un_your_api_key'
  DEFAULT_FROM_EMAIL = 'hello@yourdomain.com'
  ```

  ```ruby Ruby on Rails theme={null}
  # config/environments/production.rb
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: 'smtp.unosend.co',
    port: 587,
    user_name: 'emailapikey',
    password: 'un_your_api_key',
    authentication: :plain,
    enable_starttls_auto: true
  }
  ```

  ```text Supabase theme={null}
  Host: smtp.unosend.co
  Port: 587
  Username: emailapikey
  Password: un_your_api_key
  Sender email: hello@yourdomain.com
  ```
</CodeGroup>

## Email Tracking via SMTP

Track opens and clicks for emails sent via SMTP using custom headers. Add these headers to your email message to enable tracking:

| Header                   | Values        | Description                                          |
| ------------------------ | ------------- | ---------------------------------------------------- |
| `X-Unosend-Track-Opens`  | `true` or `1` | Injects a tracking pixel to detect email opens       |
| `X-Unosend-Track-Clicks` | `true` or `1` | Rewrites links to track clicks                       |
| `X-Unosend-Tags`         | `tag1,tag2`   | Add custom tags for categorization (comma-separated) |

<Note>
  Tracking headers are automatically removed before the email is delivered, so recipients won't see them.
</Note>

### Examples with Tracking

<CodeGroup>
  ```javascript Nodemailer (Node.js) theme={null}
  const info = await transporter.sendMail({
    from: 'hello@yourdomain.com',
    to: 'user@example.com',
    subject: 'Newsletter',
    html: '<h1>Hello!</h1><p>Click <a href="https://example.com">here</a></p>',
    headers: {
      'X-Unosend-Track-Opens': 'true',
      'X-Unosend-Track-Clicks': 'true',
      'X-Unosend-Tags': 'newsletter,january'
    }
  });
  ```

  ```python Python (smtplib) theme={null}
  msg = MIMEMultipart()
  msg['From'] = 'hello@yourdomain.com'
  msg['To'] = 'user@example.com'
  msg['Subject'] = 'Newsletter'
  msg['X-Unosend-Track-Opens'] = 'true'
  msg['X-Unosend-Track-Clicks'] = 'true'
  msg['X-Unosend-Tags'] = 'newsletter,january'

  body = '<h1>Hello!</h1><p>Click <a href="https://example.com">here</a></p>'
  msg.attach(MIMEText(body, 'html'))
  ```

  ```php Laravel theme={null}
  use Illuminate\Support\Facades\Mail;
  use Illuminate\Mail\Message;

  Mail::send([], [], function (Message $message) {
      $message->to('user@example.com')
              ->subject('Newsletter')
              ->html('<h1>Hello!</h1>')
              ->getHeaders()
              ->addTextHeader('X-Unosend-Track-Opens', 'true')
              ->addTextHeader('X-Unosend-Track-Clicks', 'true');
  });
  ```

  ```ruby Ruby on Rails theme={null}
  class NewsletterMailer < ApplicationMailer
    def welcome_email(user)
      headers['X-Unosend-Track-Opens'] = 'true'
      headers['X-Unosend-Track-Clicks'] = 'true'
      headers['X-Unosend-Tags'] = 'newsletter,welcome'
      
      mail(to: user.email, subject: 'Welcome!')
    end
  end
  ```
</CodeGroup>

<Tip>
  View open and click events in your [Analytics dashboard](/analytics) or receive them via [Webhooks](/webhooks).
</Tip>

## Supported Integrations

Unosend SMTP works with any application that supports SMTP:

<CardGroup cols={4}>
  <Card title="Nodemailer" icon="node-js" iconType="brands" />

  <Card title="Laravel" icon="laravel" iconType="brands" />

  <Card title="Django" icon="python" iconType="brands" />

  <Card title="Rails" icon="gem" iconType="solid" />

  <Card title="Supabase" icon="database" iconType="solid" />

  <Card title="WordPress" icon="wordpress" iconType="brands" />

  <Card title="NextAuth" icon="shield-halved" iconType="solid" />

  <Card title="Auth0" icon="lock" iconType="solid" />

  <Card title="Strapi" icon="cube" iconType="solid" />

  <Card title="Ghost" icon="ghost" iconType="solid" />

  <Card title="Discourse" icon="comments" iconType="solid" />

  <Card title="GitLab" icon="gitlab" iconType="brands" />
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Domain Verification" href="/docs/guides/domain-verification">
    Verify your domain for better deliverability
  </Card>

  <Card title="Sending Emails" href="/docs/guides/sending-emails">
    Learn about advanced email options
  </Card>
</CardGroup>
