I'm trying to setup ssmtp (for sendmail) in Docker image.

To do so I've created the folowing Dockerfile:

FROM php:7.4-apache

# Install paquet requirements
RUN set -ex; \
    # Install required system packages
    apt-get update; \
    apt-get install -qy --no-install-recommends \
            ssmtp \
            mailutils \
    ; \
    # Clean aptitude cache and tmp directory
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*;

As you can see I have installed ssmtp and mailutils.

My /etc/ssmtp.conf file contains all credentials that I can log into my account using standard mail client:

[email protected]

[email protected]




From some reason mail is not sent. I'm tying with sendmail command:

sendmail [email protected]
Subject: aaa

and getting error:

sendmail: Authorization failed (535 Incorrect authentication data)

Even Debug=YES is set, I do not see any log under /var/log regarding sendmail.

However, when I am trying to use ssmtp command in verbose mode, the folowing logs are produced:

root@c7e406d765c1:/app# ssmtp -d9 [email protected]
[<-] 220 ****.com ESMTP Exim Fri, 15 Apr 2022 12:25:49 +0200
[->] EHLO ****.com
[<-] 250 HELP
[<-] 334 VXNl[*** tuncated here ***]
[->] c2Vyd2VyDQ==
[<-] 334 UGFz[*** tuncated here ***]
[<-] 535 Incorrect authentication data
ssmtp: Authorization failed (535 Incorrect authentication data)

This is quite strange because same credentials (from config) works for instance in PHPMailer configuration.

Do you have any thought what might be wrong?

Thank you all!

2 Answers 2


It looks like ssmtp is trying to authenticate without sending the STARTTLS command first. Normally, when port 587 is used, the incoming connection is expected to first send a plaintext EHLO, then a STARTTLS if authentication is going to be needed.

With SMTP, straight TLS without a STARTTLS-style initiation is normally expected when using port 465 (a.k.a smtps).

Have you tried uncommenting the UseSTARTTLS=YES line?

Your Docker image might also need the public SSL/TLS root certificates, so that ssmtp will be able to validate the mail server's certificate when connecting to it. Being unable to do so might also cause ssmtp to fall back to connecting without encryption, which is likely to fail at the authentication step if the server side is configured to the best practice of "no authentication without encryption".

  • thank you for explanation of the flow. I have tried with uncommenting UseSTARTTLS=YES line on port 587, however the flow is exactly the same. In essence changing UseSTARTTLS does not change output. I have also tried with connection to 465 port, but in this case command ssmtp -d9 EMAIL after hitting ctrl+d instead of start communicating with ssmtp, completely hangs without giving any output.
    – Athlan
    Apr 20, 2022 at 10:29
  • I have also checked and I see certs in /etc/ssl/certs and they are up to date: ``` root@def565e2d922:/etc/ssl/certs# apt-get install ca-certificates Reading package lists... Done Building dependency tree... Done Reading state information... Done ca-certificates is already the newest version (20210119). 0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded. ```
    – Athlan
    Apr 20, 2022 at 10:39

I have solved my problem. Issue was Windows line ending of ssmtp.conf file.

It explains why username was not correct and why Debug flag and UseSTARTTLS flag changes were not respected.

Many thanks to @telcoM for a way to debug server flow.

  • Thank you so much for this answer you gave to yourself. - I have spend two hours now figuring out why ssmtp was working when manual installed into a running container but not when installed from image build script. (And of course is was windows line endings.. what a miserable behavior of this utility!)
    – JPS
    Jun 23, 2022 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .