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

# SMTP

> Send emails using SendKit's SMTP relay instead of the REST API.

## What is SMTP sending?

SendKit provides an SMTP relay that lets you send emails using standard SMTP protocol instead of the REST API. This is useful for applications, frameworks, and tools that already support SMTP out of the box — no SDK or HTTP integration needed.

Emails sent via SMTP go through the same delivery pipeline as API-sent emails: domain verification, suppression checks, tracking, and event webhooks all work the same way.

## SMTP credentials

| Setting        | Value                                                    |
| -------------- | -------------------------------------------------------- |
| **Host**       | `smtp.sendkit.dev`                                       |
| **Ports**      | `465` (SSL), `587` (STARTTLS), `2587` (STARTTLS)         |
| **Username**   | `sendkit`                                                |
| **Password**   | Your API key (e.g., `sk_xxxxxxxx...`)                    |
| **Encryption** | Implicit TLS on port 465, STARTTLS on ports 587 and 2587 |

<Note>
  Your SMTP password is your API key. The same key you use for the REST API works for SMTP authentication. The permission level and domain scope of the key apply to SMTP as well.
</Note>

## Port selection

| Port     | Protocol           | When to use                                                              |
| -------- | ------------------ | ------------------------------------------------------------------------ |
| **465**  | Implicit TLS (SSL) | Preferred for most applications. Connection is encrypted from the start  |
| **587**  | STARTTLS           | Standard submission port. Starts unencrypted, upgrades to TLS            |
| **2587** | STARTTLS           | Alternative to 587 when your network or hosting provider blocks port 587 |

All three ports deliver emails identically. Pick whichever one your application or network supports.

## Configuration examples

<Tabs>
  <Tab title="Laravel">
    In your `.env` file (Laravel 11+):

    ```env theme={null}
    MAIL_MAILER=smtp
    MAIL_HOST=smtp.sendkit.dev
    MAIL_PORT=465
    MAIL_USERNAME=sendkit
    MAIL_PASSWORD=sk_your_api_key_here
    MAIL_SCHEME=smtps
    ```

    If you're using port 587 (STARTTLS) instead:

    ```env theme={null}
    MAIL_MAILER=smtp
    MAIL_HOST=smtp.sendkit.dev
    MAIL_PORT=587
    MAIL_USERNAME=sendkit
    MAIL_PASSWORD=sk_your_api_key_here
    MAIL_SCHEME=smtp
    ```

    For Laravel 10 and earlier, use `MAIL_ENCRYPTION=ssl` (port 465) or `MAIL_ENCRYPTION=tls` (port 587) instead of `MAIL_SCHEME`.
  </Tab>

  <Tab title="Node.js">
    Using [Nodemailer](https://nodemailer.com):

    ```javascript theme={null}
    const transporter = nodemailer.createTransport({
      host: "smtp.sendkit.dev",
      port: 465,
      secure: true,
      auth: {
        user: "sendkit",
        pass: "sk_your_api_key_here",
      },
    });

    await transporter.sendMail({
      from: "you@yourdomain.com",
      to: "recipient@example.com",
      subject: "Hello from SendKit",
      html: "<p>Hello!</p>",
    });
    ```
  </Tab>

  <Tab title="Python">
    Using Django in `settings.py`:

    ```python theme={null}
    EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
    EMAIL_HOST = "smtp.sendkit.dev"
    EMAIL_PORT = 465
    EMAIL_USE_SSL = True
    EMAIL_HOST_USER = "sendkit"
    EMAIL_HOST_PASSWORD = "sk_your_api_key_here"
    ```

    Using `smtplib` directly:

    ```python theme={null}
    import smtplib
    from email.mime.text import MIMEText

    msg = MIMEText("<p>Hello!</p>", "html")
    msg["Subject"] = "Hello from SendKit"
    msg["From"] = "you@yourdomain.com"
    msg["To"] = "recipient@example.com"

    with smtplib.SMTP_SSL("smtp.sendkit.dev", 465) as server:
        server.login("sendkit", "sk_your_api_key_here")
        server.send_message(msg)
    ```
  </Tab>

  <Tab title="PHP">
    Using [PHPMailer](https://github.com/PHPMailer/PHPMailer):

    ```php theme={null}
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host       = 'smtp.sendkit.dev';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'sendkit';
    $mail->Password   = 'sk_your_api_key_here';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port       = 465;

    $mail->setFrom('you@yourdomain.com');
    $mail->addAddress('recipient@example.com');
    $mail->Subject = 'Hello from SendKit';
    $mail->isHTML(true);
    $mail->Body = '<p>Hello!</p>';

    $mail->send();
    ```
  </Tab>

  <Tab title="Ruby">
    Using Action Mailer in `config/environments/production.rb`:

    ```ruby theme={null}
    config.action_mailer.smtp_settings = {
      address: "smtp.sendkit.dev",
      port: 465,
      user_name: "sendkit",
      password: "sk_your_api_key_here",
      ssl: true
    }
    ```

    Using `net/smtp` directly:

    ```ruby theme={null}
    require "net/smtp"

    message = "From: you@yourdomain.com\r\n" \
              "To: recipient@example.com\r\n" \
              "Subject: Hello from SendKit\r\n" \
              "Content-Type: text/html\r\n" \
              "\r\n" \
              "<p>Hello!</p>"

    smtp = Net::SMTP.new("smtp.sendkit.dev", 465)
    smtp.enable_tls
    smtp.start("smtp.sendkit.dev", "sendkit", "sk_your_api_key_here", :login) do |s|
      s.send_message(message, "you@yourdomain.com", "recipient@example.com")
    end
    ```
  </Tab>

  <Tab title="Go">
    Using [go-mail](https://github.com/wneessen/go-mail):

    ```go theme={null}
    package main

    import (
        "log"

        "github.com/wneessen/go-mail"
    )

    func main() {
        m := mail.NewMsg()
        m.From("you@yourdomain.com")
        m.To("recipient@example.com")
        m.Subject("Hello from SendKit")
        m.SetBodyString(mail.TypeTextHTML, "<p>Hello!</p>")

        c, err := mail.NewClient("smtp.sendkit.dev",
            mail.WithPort(465),
            mail.WithSMTPAuth(mail.SMTPAuthLogin),
            mail.WithSSLPort(false),
            mail.WithTLSPortPolicy(mail.TLSMandatory),
            mail.WithUsername("sendkit"),
            mail.WithPassword("sk_your_api_key_here"),
        )
        if err != nil {
            log.Fatal(err)
        }

        if err := c.DialAndSend(m); err != nil {
            log.Fatal(err)
        }
    }
    ```
  </Tab>

  <Tab title="Java">
    Using [Jakarta Mail](https://jakartaee.github.io/mail-api/):

    ```java theme={null}
    import jakarta.mail.*;
    import jakarta.mail.internet.*;
    import java.util.Properties;

    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.sendkit.dev");
    props.put("mail.smtp.port", "465");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.ssl.enable", "true");

    Session session = Session.getInstance(props, new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("sendkit", "sk_your_api_key_here");
        }
    });

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("you@yourdomain.com"));
    message.setRecipient(Message.RecipientType.TO,
        new InternetAddress("recipient@example.com"));
    message.setSubject("Hello from SendKit");
    message.setContent("<p>Hello!</p>", "text/html");

    Transport.send(message);
    ```
  </Tab>

  <Tab title="Rust">
    Using [lettre](https://crates.io/crates/lettre):

    ```rust theme={null}
    use lettre::{
        message::header::ContentType,
        transport::smtp::authentication::Credentials,
        Message, SmtpTransport, Transport,
    };

    let email = Message::builder()
        .from("you@yourdomain.com".parse().unwrap())
        .to("recipient@example.com".parse().unwrap())
        .subject("Hello from SendKit")
        .header(ContentType::TEXT_HTML)
        .body("<p>Hello!</p>".to_string())
        .unwrap();

    let creds = Credentials::new(
        "sendkit".to_string(),
        "sk_your_api_key_here".to_string(),
    );

    let mailer = SmtpTransport::relay("smtp.sendkit.dev")
        .unwrap()
        .credentials(creds)
        .build();

    mailer.send(&email).unwrap();
    ```
  </Tab>

  <Tab title="Elixir">
    Using [Swoosh](https://hex.pm/packages/swoosh) with the SMTP adapter:

    ```elixir theme={null}
    # config/config.exs
    config :my_app, MyApp.Mailer,
      adapter: Swoosh.Adapters.SMTP,
      relay: "smtp.sendkit.dev",
      port: 465,
      username: "sendkit",
      password: "sk_your_api_key_here",
      ssl: true,
      tls: :never,
      auth: :always

    # lib/my_app/mailer.ex
    defmodule MyApp.Mailer do
      use Swoosh.Mailer, otp_app: :my_app
    end

    # Sending an email
    import Swoosh.Email

    new()
    |> to("recipient@example.com")
    |> from("you@yourdomain.com")
    |> subject("Hello from SendKit")
    |> html_body("<p>Hello!</p>")
    |> MyApp.Mailer.deliver()
    ```
  </Tab>

  <Tab title=".NET">
    Using [MailKit](https://github.com/jstedfast/MailKit):

    ```csharp theme={null}
    using MailKit.Net.Smtp;
    using MailKit.Security;
    using MimeKit;

    var message = new MimeMessage();
    message.From.Add(new MailboxAddress("", "you@yourdomain.com"));
    message.To.Add(new MailboxAddress("", "recipient@example.com"));
    message.Subject = "Hello from SendKit";
    message.Body = new TextPart("html") { Text = "<p>Hello!</p>" };

    using var client = new SmtpClient();
    await client.ConnectAsync("smtp.sendkit.dev", 465, SecureSocketOptions.SslOnConnect);
    await client.AuthenticateAsync("sendkit", "sk_your_api_key_here");
    await client.SendAsync(message);
    await client.DisconnectAsync(true);
    ```
  </Tab>

  <Tab title="WordPress">
    Using the [WP Mail SMTP](https://wordpress.org/plugins/wp-mail-smtp/) plugin:

    | Setting       | Value              |
    | ------------- | ------------------ |
    | SMTP Host     | `smtp.sendkit.dev` |
    | Encryption    | SSL                |
    | SMTP Port     | `465`              |
    | SMTP Username | `sendkit`          |
    | SMTP Password | Your API key       |
  </Tab>
</Tabs>

## SMTP vs API

| Feature               | SMTP                                  | API                              |
| --------------------- | ------------------------------------- | -------------------------------- |
| **Setup**             | Works with any app that supports SMTP | Requires HTTP integration or SDK |
| **Bulk sending**      | One email per SMTP session            | Up to 100 emails per request     |
| **Attachments**       | Native MIME attachments               | Base64-encoded in JSON           |
| **Templates**         | Not supported                         | Supported via `template.id`      |
| **Scheduled sending** | Not supported                         | Supported via `scheduled_at`     |
| **Tags**              | Not supported                         | Supported via `tags`             |

<Tip>
  Use the REST API when you need features like templates, scheduled sending, tags, or bulk sending. Use SMTP when you want a drop-in integration with existing applications.
</Tip>

## FAQ

<AccordionGroup>
  <Accordion title="Can I use any API key for SMTP?">
    Yes. Any valid API key works as the SMTP password. The key's permission level and domain scope are enforced — a send-only key scoped to a specific domain will only be able to send from that domain via SMTP.
  </Accordion>

  <Accordion title="Why is port 587 blocked on my server?">
    Some hosting providers (AWS, GCP, Azure) block outbound port 587 by default. Use port 465 (SSL) or 2587 (alternative STARTTLS) instead.
  </Accordion>

  <Accordion title="Do tracking and webhooks work with SMTP?">
    Yes. Open tracking, click tracking, and all webhook events (delivered, bounced, opened, clicked, etc.) work the same way as API-sent emails.
  </Accordion>

  <Accordion title="Is there a rate limit for SMTP?">
    SMTP sending follows the same rate limits as the REST API based on your plan. Each SMTP message counts as one email toward your quota.
  </Accordion>
</AccordionGroup>
