Gitea via Docker: Using sendmail for notifications

I’m running Gitea in a Docker container (setup details below). I’mm attempting to enable email notifications using Sendmail, but I fail. Gitea gives an error message when I try to send a test mail (details below). Using sendmail in the container also fails:

{host}$ docker-compose exec server /bin/bash
WARNING: The GITEA_USER_UID variable is not set. Defaulting to a blank string.
WARNING: The GITEA_USER_GID variable is not set. Defaulting to a blank string.
bash-4.3# echo "Subject: Test" | sendmail -v alice@example.org
sendmail: can't connect to remote host (127.0.0.1): Connection refused
bash-4.3#

I’ve verified that sendmail works on the host and that the message is delievered, e.g.

{host}$ echo "Subject: Test" | sendmail -v alice@example.org
Mail Delivery Status Report will be mailed to <alice>.

Questions

I’m a rookie with both Gitea and Docker.

  • Can I expect Sendmail to work with the Gitea 1.3.2 Docker container?

  • Is there anything I need to configure in my docker-compose.yml file (details below)?

  • Do I need to tweak the Dockerfile, e.g. install additional software?

My Gitea Setup

I’m running Gitea in a Docker container configured as:

$ cat docker-compose.yml 
version: "2"

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.3.2
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data:Z
    ports:
      - "8080:3000"
      - "2022:22"
    environment:
      - USER_UID=${GITEA_USER_UID}
      - USER_GID=${GITEA_USER_GID}

In gitea/conf/app.ini, I have:

[mailer]
ENABLED = true
USE_SENDMAIL = true
FROM = test@example.org
SENDMAIL_PATH = /usr/sbin/sendmail

After restarting, The ‘Mailer Configuration’ panel under ‘Configuration’ shows:

Enabled                    : [x]
Name                       : Gitea Hub
Use                        : Sendmail
Sendmail Path              : /usr/sbin/sendmail
Extra arguments to Sendmail: []
User:                      : (empty)

When I enter am email address and hit ‘Send Test Mail’, the ‘Configuration’ page responds with error: “Failed to send test email to ‘alice@example.org’: gomail: could not send email 1: exit status 1”.

I’ve solved this. There were two things that needed to be solved.

  1. Previously I was running the Docker daemon with iptables: false set in /etc/docker/daemon.json (corresponding to Dockers’ command-line option --iptables=true). This prevented sendmail from Docker to access external hosts. It was not even possible ping outside the host.

  2. I’ve got access to an external SMTP server which have sendmail use by setting SENDMAIL_ARGS = -S smtp.example.org in gitea/conf/app.ini. (Using HOST = smtp.example.org:25 was ignored, so had to use SENDMAIL_ARGS).

The following is what I now have in gitea/conf/app.ini and what works:

[mailer]
ENABLED = true
USE_SENDMAIL = true
FROM = test@example.org
SENDMAIL_PATH = /usr/sbin/sendmail
SENDMAIL_ARGS = -S smtp.example.org

I’m running the Docker Gitea 1.3.2 image.

1 Like

However, when I use Sendmail, which is BusyBox’s Sendmail when run from the Docker container, I have the following issues:

  1. On the receiving end, the text/html content is rendered as text/plain, so very “cluttered” messages go out this way. I don’t know if this is an issue with BusyBox Sendmail, or the SMTP server. When using sendmail -v, the output looks fine to me.

  2. When sending to a @gmail.com account, Google/Gmail refuses to receive the message because it’s “non-RFC 5322 compliant” due to “‘From’ header is missing.”. I also don’t know why this is because, again, the sendmail -v output looks fine and there is indeed a From: line sent in addition to a MAIL FROM: line.

Final-Recipient: rfc822;alice...@gmail.com
Action: failed
Status: 5.5.0
Diagnostic-Code: smtp;550-5.7.1 [169.230.134.150      11] Our system has detected that this message is
550-5.7.1 not RFC 5322 compliant:
550-5.7.1 'From' header is missing.
550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been
550-5.7.1 blocked. Please visit
550-5.7.1  https://support.google.com/mail/?p=RfcMessageNonCompliant
550 5.7.1 and review RFC 5322 specifications for more information. a23si1019813pff.83 - gsmtp

Updating my gitea/conf/app.ini to not use Sendmail, but go directly to the SMTP server, solves both problems: HTML messages are going out as proper text/html and Gmail is happy and delivers it. To conclude, the following seems to work from within Gitea Docker:

[mailer]
ENABLED = true
FROM = test@example.org
USE_SENDMAIL = false
HOST = smtp.example.org:25
1 Like