# Send your first email over SMTP

> Get your SMTP credentials, pick a port and send a test email through smtp.emailit.com with swaks, OpenSSL or Python, then connect your app or framework.

This quickstart shows you how to send a test email through the Emailit SMTP relay from your terminal, then connect your own app. Use SMTP when your software already has SMTP settings. For new code, the [API](/docs/quickstart/api/) does more.

## Before you begin

- A verified sending domain. If you don't have one yet, follow the first section of the [API quickstart](/docs/quickstart/api/#add-and-verify-your-domain) or [Add a domain](/docs/domains/add-a-domain/).
- An API key. Create one in **Email API → API Keys** with **Add API key**. Your API key is your SMTP password.

## Your SMTP credentials

| Setting | Value |
| --- | --- |
| Host | `smtp.emailit.com` |
| Port | `587` with STARTTLS (recommended). See the table below for alternatives. |
| Username | `emailit` |
| Password | Your API key, starting with `secret_` |
| Authentication | `PLAIN` or `LOGIN` |
| From address | Any address on a verified sending domain, for example `Acme <hello@acme.com>` |

You can also see these settings on the **SMTP Info** card when you open a key in **Email API → API Keys**.

| Port | Encryption | When to use it |
| --- | --- | --- |
| `587` | STARTTLS | The default for most apps and libraries |
| `465` | TLS from the first byte (implicit TLS) | When your client calls it "SSL" or "SMTPS" |
| `2525` | STARTTLS | When your network or hosting provider blocks 587 |
| `2587` | STARTTLS | Another alternative when 587 and 2525 are blocked |
| `25` | STARTTLS | Server-to-server relaying. Many cloud providers block outbound port 25. |

The relay offers TLS on every port but doesn't force it. Always turn TLS on in your client so your API key isn't sent in plain text.

## Send a test email

Pick one of these tools. Replace `hello@acme.com` with an address on your verified domain, and `ada@example.com` with the email address you signed up with.

> **Sandbox mode:** Until your workspace has production access, you can only send to the account email addresses of workspace members. Other recipients are refused with `550 Unverified workspaces can only send to workspace members' account emails`. See [Production access](/docs/workspaces/production-access/).

### swaks

[swaks](https://github.com/jetmore/swaks) is a command-line SMTP test tool. Install it with `brew install swaks` or `apt install swaks`, then run:

```bash
swaks --server smtp.emailit.com:587 --tls \
  --auth-user emailit --auth-password "$EMAILIT_API_KEY" \
  --from hello@acme.com --to ada@example.com \
  --header "Subject: Hello from Emailit SMTP" \
  --body "This is my first email sent through the Emailit SMTP relay."
```

swaks prints the whole SMTP conversation. The last reply from the server contains the email ID:

```text
<~  250 2.0.0 OK: queued as em_2pX7cN4kQ9vLm3RtB8yWd1Zs
```

### OpenSSL

OpenSSL is preinstalled on most systems and lets you type the SMTP commands yourself. First, encode your credentials for `AUTH PLAIN`:

```bash
printf '\0emailit\0%s' "$EMAILIT_API_KEY" | base64
```

Then open a connection and type the commands below, pasting the encoded string after `AUTH PLAIN`:

```bash
openssl s_client -connect smtp.emailit.com:587 -starttls smtp -crlf -quiet
```

```text
EHLO localhost
AUTH PLAIN AGVtYWlsaXQAc2VjcmV0X...
MAIL FROM:<hello@acme.com>
RCPT TO:<ada@example.com>
DATA
From: Acme <hello@acme.com>
To: ada@example.com
Subject: Hello from Emailit SMTP

This is my first email sent through the Emailit SMTP relay.
.
QUIT
```

After `AUTH PLAIN` the server answers `235`. After the line with a single `.`, it answers `250 2.0.0 OK: queued as em_…`.

### Python

Python's built-in `smtplib` needs no extra packages:

```python title="send_smtp.py"
from email.message import EmailMessage

msg = EmailMessage()
msg["From"] = "Acme <hello@acme.com>"
msg["To"] = "ada@example.com"
msg["Subject"] = "Hello from Emailit SMTP"
msg.set_content("This is my first email sent through the Emailit SMTP relay.")
msg.add_alternative("<p>This is my first email sent through the Emailit SMTP relay.</p>", subtype="html")

with smtplib.SMTP("smtp.emailit.com", 587) as smtp:
    smtp.starttls()
    smtp.login("emailit", os.environ["EMAILIT_API_KEY"])
    smtp.send_message(msg)

print("Accepted by Emailit")
```

If the script finishes without an exception, Emailit has accepted the email.

## Check it in the dashboard

Go to **Email API → Emails**. Your email is at the top of the **Outgoing** tab, and its status changes from **accepted** to **delivered** once the recipient's server accepts it. Each SMTP session also appears in **Email API → Logs** with the source **SMTP**, so you can see failed logins and rejected messages too.

## Common replies

| Reply | Cause | Fix |
| --- | --- | --- |
| `535 Authentication failed` | Wrong or deleted API key | Use a current API key as the password. See [535 errors](/docs/kb/smtp-535-authentication-failed/). |
| `530 From/Sender domain is not verified for this workspace` | The From address isn't on a verified domain | Verify the domain, or change the From address. See [530 errors](/docs/kb/smtp-530-from-domain-not-verified/). |
| `550 Unverified workspaces can only send to workspace members' account emails` | Sandbox mode | Send to a member's account email, or request production access |
| `452 4.4.5 Messages per second limit exceeded` | More than your per-second limit | Slow down and retry. Limits are shared with the API. |
| `452 4.5.3 Daily message limit exceeded` | You reached today's limit | Wait until midnight UTC, or [request an increase](/docs/limits/) |
| Connection timeout | Your network blocks the port | Try `2525` or `2587`. See [Connection timeouts](/docs/kb/smtp-connection-timeout-port-25/). |

For every reply code, see [SMTP troubleshooting](/docs/smtp/troubleshooting/).

## Connect your app

Put the same settings into your app or framework. These guides show the exact configuration:

  - [Laravel](/docs/frameworks/laravel/)
  - [PHP](/docs/frameworks/php/)
  - [WordPress](/docs/frameworks/wordpress/)
  - [Node.js](/docs/frameworks/nodejs/)
  - [Next.js](/docs/frameworks/nextjs/)
  - [Nuxt](/docs/frameworks/nuxt/)
  - [Python](/docs/frameworks/python/)
  - [Rails](/docs/frameworks/rails/)
  - [Go](/docs/frameworks/go/)
  - [Java](/docs/frameworks/java/)
  - [.NET](/docs/frameworks/dotnet/)

## Next steps

  - [SMTP settings](/docs/smtp/settings/): Ports, TLS, message size and how Emailit treats your headers.
  - [SMTP headers](/docs/smtp/headers/): Which headers Emailit adds, changes or removes.
  - [Set up webhooks](/docs/webhooks/set-up/): Get delivery and bounce events for SMTP email too.
  - [API or SMTP](/docs/get-started/api-or-smtp/): What the API can do that SMTP can't.

---
Source: https://emailit.com/docs/quickstart/smtp/
