SMTP gate
What is an SMTP gate
SMTP-gate is a way to send us jobs to send emails via the SMTP protocol. The difference between API and SMTP is the data transfer protocol used: SMTP or HTTP protocol. With the SMTP protocol, a sequence of commands is used to send to the server.
enKod supports:
- sending emails using the following protocols: SMTP, TLS 1.2+ (port 587), and SSL (port 465)
- sending HTML emails with attachments (up to 25 MB)
- SSL/TLS connection encryption
- maintaining audit logs of operations: sending, errors
Authorisation and sending a message
The enKod authentication is done using SMTP keys. Obtain an SMTP key from your personal SMTP manager to use the SMTP gateway.
Connect to the SMTP server at address: smtpgateway.enkod.io:587
Use the following command sequence:
STARTTLS- after entering this command, all further communication between the client and the server takes place via encrypted TLS protocol.EHLO- welcome message, in response we receive a list of server settingsAUTH PLAIN- base64 encoded login and password (only SMTP API key as password is required for authentication, login is left blank)MAIL FROM- email address from which the message will be sentRCPT TO- email address to which the message is to be sentDATA- after entering this command you can enter the message body with headers.
Example of a request to send via openssl
s_client -starttls smtp -connect smtpgateway.enkod.ru:587
ehlo testmail.ru
auth plain AABfN3lhTUZtcm5hZ251VFRXR1lueVNiQWNLX2R4VTh4WWVYdzV2UzBYXVpMQ==
mail from:test@testmail.ru
rcpt to:test2@testmail.ru
data
Date: Thu, 29 Sep 2022 15:42:13 GMT
From: test@testmail.ru
To: test2@testmail.ru
Subject: subject
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" style="font-family:'open sans', 'helvetica neue', helvetica, arial, sans-serif">
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta name="x-apple-disable-message-reformatting"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta content="telephone=no" name="format-detection"/>
<title>title</title><!--[if (mso 16)]>
<style type="text/css">
a {text-decoration: none;}
</head>
<html>
<body>
message body
</body>
</html>
Features of displaying message subjects and senders
Yandex has updated its rules for processing email subjects:
- UTF-8 encoding cannot be used
- It is recommended to format email headers and bodies in accordance with RFC standards, with non-printable characters escaped. This means that base64 encoding must be used for the message subject and sender if they are written in Cyrillic.
You can use the following structure:
=?charset?encoding?encoded-text?=
For example, send the subject as:
Subject: =?utf-8?B?0KLQtdGB0YIgU01UUCDlhbzQvNC+0LQ=?=
- =? — beginning of the encoded word
- charset — utf-8 (character encoding)
- encoding — B (encoding method)
- encoded-text — 0KLQtdGB0YIgU01UUCDlhbzQvNC+0LQ (encoded text in base64)
- ?= — end of encoded word
If the address in the From field is not formed using the RFC standard, it will be marked as EMPTY-FROM. The email properties will also contain From: EMPTY-FROM.
Possible errors
invalid from email- the sending email does not match the structure of name@domain.com.no username or password- AUTH PLAIN authentication is not used.api key doesn't have accesses- no SMTP access for API keyclient is deleted- account is inactive or deletedinternal service error- internal service errorwrong api key- API key is invalid
Message sending process
Request → enKod → Receiving mail server
Step 1. enKod checks the received request (whether the API key is valid, whether the specified email addresses are valid, etc.).
- If the check fails, we return an error from the list above.
- If the check passes, the request is processed successfully, and the message is placed in the enKod queue.
Step 2. enKod attempts to contact the mail server.
The final delivery status depends on many factors (the sender's domain reputation, the existence of the recipient's mailbox, etc.). Additionally, the receiving mail server may ask to send the email later — for this, we use our own forwarding mechanism. This process can take a long time, so in order not to delay the response, enKod performs initial checks in step 1 and responds that everything worked correctly.
After the letter has been sent, we do not immediately return the error that occurred on the mail server side. Because of this, the request may be processed successfully, but the error will be reflected in the statistics.
To get information about the final delivery status of a message, you can configure Webhooks.