SMTP relay
Some apps and tools can only send email over SMTP. Point them at the Sendfern SMTP relay with an API key as the password, and every message goes through the same checks, events and webhooks as POST /v1/emails.
Connection settings
| Setting | Value |
|---|---|
| Host | smtp.sendfern.com |
| Port | 587 with STARTTLS, or 465 with TLS from the start |
| Encryption | Required. The relay refuses to log in before the connection is encrypted. |
| Authentication | AUTH PLAIN or AUTH LOGIN |
| Username | Anything. It is ignored, so use something readable such as sendfern. |
| Password | An API key (sk_live_... or sk_test_...) |
The examples on this page read the key from the SENDFERN_API_KEY environment variable.
Which key to use
Any key works, including a send-only key, which is the best choice for SMTP: it can send but can't read or change anything else. The key's mode applies, so a test key simulates the send without delivering anything. Live sends need an approved account and a verified domain for the From address, exactly like the API. See Authentication and Domains and DNS.
Three wrong passwords in one connection close it. A key revoked while a connection is open stops working at the next message.
Send a message
A message sent with cURL from a file:
From: Acme <hello@acme.com> To: user@example.com Subject: Your order has shipped Content-Type: text/plain; charset=utf-8 Your order is on its way.
# message.txt holds the message shown above.
curl "smtp://smtp.sendfern.com:587" \
--ssl-reqd \
--user "sendfern:$SENDFERN_API_KEY" \
--mail-from "hello@acme.com" \
--mail-rcpt "user@example.com" \
--upload-file message.txtWhen the relay accepts a message it answers 250 2.0.0 OK queued as em_.... The id is a normal email id: look it up with GET /v1/emails/{id} or under Emails in the dashboard, and receive its events with webhooks.
Django
Django's built-in SMTP backend works without extra packages. send_mail and EmailMessage then go through Sendfern.
# settings.py import os EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" EMAIL_HOST = "smtp.sendfern.com" EMAIL_PORT = 587 EMAIL_USE_TLS = True # STARTTLS. For port 465 use EMAIL_USE_SSL = True instead. EMAIL_HOST_USER = "sendfern" # any username works EMAIL_HOST_PASSWORD = os.environ["SENDFERN_API_KEY"] DEFAULT_FROM_EMAIL = "Acme <hello@acme.com>"
Other apps
Any app with SMTP settings works: use the values from Connection settings. If the app asks for an encryption type, pick STARTTLS (or TLS) for port 587, and SSL/TLS for port 465. Never pick "none": the relay won't accept your login.
How messages are converted
Each message becomes a send, built from the message like this:
- From, To, Cc, Reply-To and Subject come from the message headers.
- Body: the plain-text part becomes
textand the HTML parthtml. - Attachments come from the attachment parts.
- Recipients come from the envelope (
RCPT TO), not the headers. An address in the To or Cc header that is also in the envelope keeps its place. Envelope recipients that aren't in a header are sent as Bcc. An address that is only in a header gets nothing.
Mail libraries such as Nodemailer and Python's smtplib build the envelope from To, Cc and Bcc for you, so you rarely need to think about it. It matters when you set the envelope yourself, as with cURL's --mail-rcpt.
The message is checked against the same rules as an API request: validation, the live sending checks, your monthly quota and the per-account rate limit (shared with your API requests). Suppressed recipients are dropped at send time, as with any send. See Suppressions and Rate limits and quotas.
Limits
| Limit | Value |
|---|---|
| Recipients per message | 50 (To, Cc and Bcc together) |
| Message size | 10 MB, including attachments |
| Idle connection | Closed after 5 minutes without a command |
Reply codes
Codes starting with 4 are temporary: your client should retry later. Codes starting with 5 are permanent: fix the message or settings first. For 550, the text is the same message the API would return.
| Code | Meaning |
|---|---|
235 | Logged in. |
250 | Accepted. 2.0.0 OK queued as em_... after the message. |
421 | Connection closed: three failed logins, or idle too long. Reconnect. |
451 | Rate limited. Try again shortly. |
452 | Too many recipients. Send the rest in another message. |
530 | Log in before sending. |
535 | Login failed or the key has been revoked. Check the API key. |
538 | Encryption required. Use STARTTLS or port 465 before logging in. |
550 | The send was refused, for example an invalid address, an unverified domain (domain_not_verified), an account awaiting approval or an exceeded quota. |
552 | Message too big (over 10 MB). |
554 | The message could not be parsed. |
Next steps
Track what happens to each message with Email lifecycle and Webhooks. If you can call an HTTP API, the Node.js and Python SDKs give you every sending option.