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

# Framework and CMS settings

> SMTP settings for Nodemailer, Laravel, Django, Ruby on Rails, WordPress (WP Mail SMTP) and PHPMailer.

These settings connect common frameworks and plugins to the Brudcast [SMTP relay](/developers/sending/smtp-relay).
Each uses port 587 with STARTTLS. Port 465 settings follow each example.

<Info>
  **Before you start**, create an SMTP user on your verified domain under **Channels > Email**,
  domain, **SMTP Credentials**. You need its username and password, and a from address on the same
  domain. See [SMTP relay](/developers/sending/smtp-relay#get-smtp-credentials).
</Info>

<Warning>
  The relay delivers only To and Cc recipients, and drops `Reply-To` and custom headers. A framework's
  `bcc` option or reply-to setting won't work over SMTP. If you need either, call the
  [email send API](/developers/sending/http-api) instead.
</Warning>

The examples read credentials from `BRUDCAST_SMTP_USERNAME` and `BRUDCAST_SMTP_PASSWORD`. Keep the
password out of source control.

<Tabs>
  <Tab title="Nodemailer">
    ```javascript theme={"system"}
    import nodemailer from "nodemailer";

    const transporter = nodemailer.createTransport({
      host: "out-smtp.prod.brudcast.com",
      port: 587,
      secure: false, // connect in plain text, then upgrade with STARTTLS
      requireTLS: true, // refuse to continue if STARTTLS fails
      auth: {
        user: process.env.BRUDCAST_SMTP_USERNAME,
        pass: process.env.BRUDCAST_SMTP_PASSWORD,
      },
    });

    await transporter.sendMail({
      from: '"Example" <hello@mail.example.com>',
      to: "jane@example.com",
      subject: "Hello from Brudcast",
      text: "It works.",
      html: "<p>It works.</p>",
    });
    ```

    For port 465, set `port: 465` and `secure: true`, and remove `requireTLS`.
  </Tab>

  <Tab title="Laravel">
    In `.env`:

    ```bash theme={"system"}
    MAIL_MAILER=smtp
    MAIL_HOST=out-smtp.prod.brudcast.com
    MAIL_PORT=587
    MAIL_USERNAME=a1b2c3d4@mail.example.com
    MAIL_PASSWORD=your_smtp_password
    MAIL_FROM_ADDRESS=hello@mail.example.com
    MAIL_FROM_NAME="${APP_NAME}"
    # Laravel 10 and earlier also need:
    MAIL_ENCRYPTION=tls
    ```

    Laravel upgrades the connection with STARTTLS on port 587 automatically. For port 465, set
    `MAIL_PORT=465`.

    After changing `.env` in production, run `php artisan config:clear` so the new values load.
  </Tab>

  <Tab title="Django">
    In `settings.py`:

    ```python theme={"system"}
    import os

    EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
    EMAIL_HOST = "out-smtp.prod.brudcast.com"
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True  # STARTTLS
    EMAIL_HOST_USER = os.environ["BRUDCAST_SMTP_USERNAME"]
    EMAIL_HOST_PASSWORD = os.environ["BRUDCAST_SMTP_PASSWORD"]
    DEFAULT_FROM_EMAIL = "Example <hello@mail.example.com>"
    ```

    For port 465, set `EMAIL_PORT = 465`, `EMAIL_USE_SSL = True` and `EMAIL_USE_TLS = False`.
    Django won't accept both set to `True`.
  </Tab>

  <Tab title="Ruby on Rails">
    In `config/environments/production.rb`:

    ```ruby theme={"system"}
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      address: "out-smtp.prod.brudcast.com",
      port: 587,
      user_name: ENV["BRUDCAST_SMTP_USERNAME"],
      password: ENV["BRUDCAST_SMTP_PASSWORD"],
      authentication: :plain,
      enable_starttls_auto: true
    }
    ```

    Set the from address in your mailer:

    ```ruby theme={"system"}
    class ApplicationMailer < ActionMailer::Base
      default from: "Example <hello@mail.example.com>"
    end
    ```

    For port 465, set `port: 465` and `tls: true`, and remove `enable_starttls_auto`.
  </Tab>

  <Tab title="WordPress">
    Install the **WP Mail SMTP** plugin, then open **WP Mail SMTP > Settings** and fill in:

    | Setting              | Value                                                           |
    | -------------------- | --------------------------------------------------------------- |
    | **From Email**       | `hello@mail.example.com`, an address on your SMTP user's domain |
    | **Force From Email** | On, so other plugins can't send from another domain             |
    | **From Name**        | Your site or company name                                       |
    | **Mailer**           | **Other SMTP**                                                  |
    | **SMTP Host**        | `out-smtp.prod.brudcast.com`                                    |
    | **Encryption**       | **TLS**                                                         |
    | **SMTP Port**        | `587`                                                           |
    | **Auto TLS**         | On                                                              |
    | **Authentication**   | On                                                              |
    | **SMTP Username**    | Your SMTP user's username                                       |
    | **SMTP Password**    | Your SMTP user's password                                       |

    Save, then send a test from the plugin's **Email Test** tab.

    For port 465, set **Encryption** to **SSL** and **SMTP Port** to `465`.

    To keep the password out of the database, define it in `wp-config.php` instead:

    ```php theme={"system"}
    define( 'WPMS_ON', true );
    define( 'WPMS_SMTP_PASS', 'your_smtp_password' );
    ```
  </Tab>

  <Tab title="PHPMailer">
    ```php theme={"system"}
    <?php
    use PHPMailer\PHPMailer\PHPMailer;

    require "vendor/autoload.php";

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = "out-smtp.prod.brudcast.com";
    $mail->Port = 587;
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->SMTPAuth = true;
    $mail->Username = getenv("BRUDCAST_SMTP_USERNAME");
    $mail->Password = getenv("BRUDCAST_SMTP_PASSWORD");

    $mail->setFrom("hello@mail.example.com", "Example");
    $mail->addAddress("jane@example.com", "Jane");
    $mail->Subject = "Hello from Brudcast";
    $mail->isHTML(true);
    $mail->Body = "<p>It works.</p>";
    $mail->AltBody = "It works.";

    $mail->send();
    ```

    For port 465, set `$mail->Port = 465` and `$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS`.
  </Tab>
</Tabs>

## If it doesn't work

<AccordionGroup>
  <Accordion title="“535 Invalid credentials”" icon="circle-alert">
    **Why:** The username or password is wrong, or the SMTP user is deactivated.

    **Fix:** Use the SMTP user's generated username, not your own email address. If you've lost
    the password, regenerate it on the **SMTP Credentials** tab.
  </Accordion>

  <Accordion title="“538 Error: Must issue a STARTTLS command first”" icon="circle-alert">
    **Why:** The client tried to log in before encrypting the connection.

    **Fix:** Turn on STARTTLS or TLS in your client's settings, or switch to port 465 with SSL/TLS.
  </Accordion>

  <Accordion title="“550 MAIL FROM domain does not match authenticated domain”" icon="circle-alert">
    **Why:** The from address isn't on the SMTP user's domain.

    **Fix:** Send from an address on that domain. In WordPress, turn on **Force From Email**.
  </Accordion>

  <Accordion title="The connection times out" icon="circle-alert">
    **Why:** Your network or hosting provider blocks the port.

    **Fix:** Try port 2525, or 465.
  </Accordion>
</AccordionGroup>

## Related

<Columns cols={2}>
  <Card title="SMTP relay" icon="server" href="/developers/sending/smtp-relay">
    Ports, TLS, limits and every reply code.
  </Card>

  <Card title="Email send API" icon="send" href="/developers/sending/http-api">
    Send with Bcc, Reply-To and custom headers.
  </Card>

  <Card title="SMTP users" icon="key-round" href="/channels/email/smtp-users">
    Create the username and password these settings need.
  </Card>

  <Card title="Message status" icon="list-checks" href="/developers/sending/message-status">
    Follow up a message your framework sent.
  </Card>
</Columns>
