# SMTP

> Use Sendtide over SMTP: server smtp.sendtide.ch, ports 587 and 465, user sendtide, an API key as the password, headers for streams and replies on errors.

URL: https://sendtide.ch/en/docs/smtp/

If your software only speaks SMTP, such as a CMS, a shop or a printer, you send through the Sendtide gateway. It accepts the message and treats it like a MIME message sent through the API.
## Settings
| Setting | Value |
| --- | --- |
| Server | smtp.sendtide.ch |
| Port | 587 with STARTTLS or 465 with TLS (implicit) |
| User | sendtide (any user name is accepted) |
| Password | an API key with at least scope send |
| Authentication | PLAIN or LOGIN |

The key brings everything with it: account, environment (test or live), scope and [restrictions](https://sendtide.ch/en/docs/authentication/#restrictions). With a test key (sk_test_…) you can try the connection without anything being delivered.
## Examples

```
swaks --server smtp.sendtide.ch --port 587 --tls \
  --auth PLAIN --auth-user sendtide --auth-password "$SENDTIDE_API_KEY" \
  --from hello@example.com --to anna@example.org \
  --header "Subject: Test over SMTP" --body "Hello Anna"
```

```
import os, smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg["From"] = "Acme <hello@example.com>"
msg["To"] = "anna@example.org"
msg["Subject"] = "Welcome"
msg.set_content("Hello Anna")

with smtplib.SMTP("smtp.sendtide.ch", 587) as s:
    s.starttls()
    s.login("sendtide", os.environ["SENDTIDE_API_KEY"])
    s.send_message(msg)
```

```
import nodemailer from "nodemailer";

const transport = nodemailer.createTransport({
  host: "smtp.sendtide.ch",
  port: 465,
  secure: true,
  auth: { user: "sendtide", pass: process.env.SENDTIDE_API_KEY },
});

await transport.sendMail({
  from: "Acme <hello@example.com>",
  to: "anna@example.org",
  subject: "Welcome",
  text: "Hello Anna",
});
```

```
<?php
// PHPMailer
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.sendtide.ch';
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = 'sendtide';
$mail->Password = getenv('SENDTIDE_API_KEY');
$mail->setFrom('hello@example.com', 'Acme');
$mail->addAddress('anna@example.org');
$mail->Subject = 'Welcome';
$mail->Body = 'Hello Anna';
$mail->send();
```
## What the gateway does
- Every message takes the same path as POST /v1/emails/mime: scopes, restrictions, suppression list, quota, logs and webhooks apply as they do for the API. In the log SMTP calls show with the method SMTP, and the emails carry the tag smtp.
- With live keys the sender must belong to a verified domain, see [Domains](https://sendtide.ch/en/docs/domains/).
- The message may be at most 10 MB (552).
- The same rate limit as the API applies: 50 messages per second per key.
- There are no templates over SMTP, the message is sent as you send it. For templates use the API.
### Avoid duplicates

Sendtide remembers the Message-ID of the message (together with a checksum of message and recipients). If your client resends a message whose reply was lost, Sendtide does not send it twice. So set a unique Message-ID that does not change on a retry. Most SMTP libraries do that anyway.
## Replies from the server
| Reply | Meaning |
| --- | --- |
| 530 5.7.0 | You did not authenticate. |
| 535 5.7.8 | The key is invalid, the account is in review (live key) or the key may not be used from this IP address. |
| 454 4.7.0 | Too many failed logins from your address: 10 in 10 minutes, then you wait. |
| 451 4.7.0 | Too many messages in a short time. Try again in a second. |
| 452 4.5.3 | A limit is reached (quota, budget). Temporary: try later or raise the limit. |
| 550 5.7.1 | The message is refused, for example because of an unverified domain. The text starts with the API error code, see [Errors and limits](https://sendtide.ch/en/docs/errors-and-limits/). |
| 552 5.3.4 | The message is larger than 10 MB. |

A 2xx reply after DATA means: accepted. The id of the email is not in the reply, you find it in the dashboard, in search and in webhooks (email_id).

Tip: If you have the choice, the API is the better interface: it returns the id at once, knows templates and batches and reports errors in a structured way. SMTP is for software that can do nothing else.
