Introduction:
In some cases it might be requested to transfer emails to another mail server using encryption (SSL/TLS).
Here is a way to do it using Sieve language which Dovecot supports:

Use a sieve script to conditionally send encrypted messages.
The script would insert a header element, called X-Requires-SSL, prompting SMTPDS (the Delivery Service) to attempt to connect to the destination using STARTTLS. If the destination does not support this, the sender receives a bounce to this effect (“destination does not support STARTTLS”).

The form of the script is as follows:
require ["editheader","variables"];
if {
addheader "X-Requires-SSL" "true";
keep;
}

E.g. force encryption if the word encrypt appears in the subject line:
if header :contains "subject" "encrypt" {
addheader "X-Requires-SSL" "true";
keep;
}

Requirements for this to work:
– Your server requires an SSL certificate
– This certificate must be configured in the Modus Console
– SMTP Encryption(TLS) must be supported