Skip to content

Missing email body when using sendmail #18024

@ben-kenney

Description

@ben-kenney

Gitea Version

1.15.7

Git Version

No response

Operating System

alpine linux (using the official gitea docker image)

How are you running Gitea?

Through the official gitea docker image

Database

PostgreSQL

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/ben-kenney/8fc6715ffd2a6c5721469772957dba2e

Description

I've configured my gitea to use sendmail. I receive email notifications but they are all missing the message body and only contain the subject line.

When I log into my gitea docker container and manually check to see if sendmail is working, I can confirm that sendmail does work BUT it requires a blank line between the subject and the message body, like this:

$ sendmail -S mail.host.com recipient@domain.com
Subject: this is the subject

The message body only appears if it follows a blank line.

The blank line before the message body appears to be important otherwise sendmail will not inlcude the message body, this is documented elsewhere (sorry I couldn't find anything more official than the linked response).

I'm curious to know if this could be the reason why I'm not able to see the email messages from gitea.

I think that emails such as this test email from gitea should likely need \n\n in front of the message body when using sendmail.

return gomail.Send(Sender, NewMessage([]string{email}, "Gitea Test Email!", "Gitea Test Email!").ToMessage())

Screenshots

Here's a screenshot of the email that I received from gitea after posting a test comment (note that the message body is blank).

gitea_email

Activity

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

It would be useful to see your configuration.

  • What are the contents of the [mailer] section in your app.ini?
  • When you say "sendmail" what are you using? (It's likely you're not running sendmail and if you are running sendmail I would strongly advise against that.)
wxiaoguang

wxiaoguang commented on Dec 19, 2021

@wxiaoguang
Contributor

It isn't that simple. Can you check the original message of the email you received and post it here?

If you run:

func TestSendmail(t *testing.T) {
	var mailService = setting.Mailer{
		FromEmail: "test@gitea.com",
	}

	setting.MailService = &mailService
	setting.Domain = "localhost"
	m := NewMessage([]string{"test@localhost"}, "Gitea Test Email!", "Gitea Test Email!").ToMessage()
	_, _ = m.WriteTo(os.Stdout)
}

You will find the output, this is what you should see in your original message.

Mime-Version: 1.0
To: test@localhost
Subject: Gitea Test Email!
Date: Sun, 19 Dec 2021 23:36:06 +0800
X-Auto-Response-Suppress: All
Message-ID: <autogen-1639928166163-44d83016484b8890@localhost>
From: test@gitea.com
Content-Type: multipart/alternative;
 boundary=cc97a50fdd9552d3694a5edd3a376972006e278d23aa2be9c97e6ca19512

--cc97a50fdd9552d3694a5edd3a376972006e278d23aa2be9c97e6ca19512
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

Gitea Test Email!
--cc97a50fdd9552d3694a5edd3a376972006e278d23aa2be9c97e6ca19512
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

Gitea Test Email!
--cc97a50fdd9552d3694a5edd3a376972006e278d23aa2be9c97e6ca19512--
added
issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detail
on Dec 19, 2021
zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

... or set "MAILER_TYPE=dummy" in app.ini

ben-kenney

ben-kenney commented on Dec 19, 2021

@ben-kenney
Author

@zeripath Here is my app.ini:

[mailer]
ENABLED = true
FROM = gitea@no-reply.com
MAILER_TYPE = sendmail
SENDMAIL_PATH = /usr/sbin/sendmail
SUBJECT_PREFIX = gitea
SENDMAIL_ARGS = -S my.mail.host
IS_TLS_ENABLED = false
SEND_AS_PLAIN_TEXT = true

when I set MAILER_TYPE = dummy, the logs show this:

2021/12/19 11:32:12 ...ices/auth/session.go:73:SessionUser() [T] Session Authorization: Logged in user 1:gitea-admin
2021/12/19 11:32:12 ...ces/mailer/mailer.go:81:NewMessageFrom() [T] NewMessageFrom (body):
Gitea Test Email!
2021/12/19 11:32:12 ...ces/mailer/mailer.go:295:Send() [I] Mail From: gitea@no-reply.com To: [user@email.com] Body: Mime-Version: 1.0\01503d
Subject: gitea Gitea Test Email!\01503d
Date: Sun, 19 Dec 2021 11:32:12 -0500\01503d
X-Auto-Response-Suppress: All\01503d
From: gitea@no-reply.com\01503d
To: user@email.com\01503d
Content-Type: text/plain; charset=UTF-8\01503d
Content-Transfer-Encoding: quoted-printable\01503d
\01503d
Gitea Test Email!

I'll need to google what \01503d is. If it represents a "blank line" then my theory isn't correct.

Here's the header from the received email that I get (there's no mention of the Gitea Test Email! message body):

MIME-Version: 1.0
From: gitea@no-reply.com
To: user@host.com
Subject: gitea Gitea Test Email!
Date: Sun, 19 Dec 2021 11:36:19 -0500
X-Auto-Response-Suppress: All
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Message-ID: e4aa4716-2c08-4143-8382-afdc56dca0dc@mail.host.com
Return-Path: gitea@no-reply.com
X-CrossPremisesHeadersFilteredBySendConnector: mail.host.com
X-OrganizationHeadersPreserved: mail.host.com
X-MS-Exchange-Organization-ExpirationStartTime: 19 Dec 2021 16:36:21.2456 (UTC)
...

Not sure if this is the issue but it goes through a MS exchange server. I suspect the MS exchange is not the issue because when I try this manually using the sendmail from the command line from within the docker container I can reproduce this issue (and also confirm that a blank line works).

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

What package is providing the /usr/sbin/sendmail command?

As I said above I'm almost certain that this is not going to be sendmail but rather some other package that provides a sendmail command.

ben-kenney

ben-kenney commented on Dec 19, 2021

@ben-kenney
Author

What package is providing the /use/sbin/sendmail command?

As I said above I'm almost certain that this is not going to be sendmail but rather some other package that provides a sendmail command.

I guess I thought gitea was the package that is providing the sendmail command. There are references to sendmail in the gitea code.

from the logs that I have it looks like it is using sendmail:

2021/12/19 07:04:01 ...ces/mailer/mailer.go:248:Send() [T] Sending with: /usr/sbin/sendmail [-f gitea@no-reply.com -i -S not_showing_mail_host not_showing_useremail@mail.domain]

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor
$ docker exec -it <gitea_container> /bin/bash
bash-5.1# /usr/sbin/sendmail --help
BusyBox v1.32.1 () multi-call binary.

Usage: sendmail [-tv] [-f SENDER] [-amLOGIN 4<user_pass.txt | -auUSER -apPASS]
		[-w SECS] [-H 'PROG ARGS' | -S HOST] [RECIPIENT_EMAIL]...

Read email from stdin and send it

Standard options:
	-t		Read additional recipients from message body
	-f SENDER	For use in MAIL FROM:<sender>. Can be empty string
			Default: -auUSER, or username of current UID
	-o OPTIONS	Various options. -oi implied, others are ignored
	-i		-oi synonym, implied and ignored

Busybox specific options:
	-v		Verbose
	-w SECS		Network timeout
	-H 'PROG ARGS'	Run connection helper. Examples:
		openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25
		openssl s_client -quiet -tls1 -connect smtp.gmail.com:465
			$SMTP_ANTISPAM_DELAY: seconds to wait after helper connect
	-S HOST[:PORT]	Server (default $SMTPHOST or 127.0.0.1)
	-amLOGIN	Log in using AUTH LOGIN
	-amPLAIN	or AUTH PLAIN
			(-amCRAM-MD5 not supported)
	-auUSER		Username for AUTH
	-apPASS 	Password for AUTH

If no -a options are given, authentication is not done.
If -amLOGIN is given but no -au/-ap, user/password is read from fd #4.
Other options are silently ignored; -oi is implied.
Use makemime to create emails with attachments.

So it's the sendmail provided by busybox

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

The \01503d is \015. The 03d is simply due to a bug in the logger which I will fix imminently.

\015 => \r so you can see that the blank line is being passed to "sendmail"

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

Not sure if this is the issue but it goes through a MS exchange server. I suspect the MS exchange is not the issue because when I try this manually using the sendmail from the command line from within the docker container I can reproduce this issue (and also confirm that a blank line works).

In your testcase are you sending lines with \r\n?

ben-kenney

ben-kenney commented on Dec 19, 2021

@ben-kenney
Author

First of all, thank you for looking into this! And now I realize what you were asking regarding the package manager.

In your testcase are you sending lines with \r\n?

No, in my test case I was invoking sendmail from the command line, not piping any text to sendmail. I literally just type this:

$ sendmail -S mail.host.com recipient@domain.com
Subject: this is the subject

The message body only appears if it follows a blank line.

What I think is happening is that \n should be used instead of \r, only reason why I say this is because on my linux terminal when I run printf "hello \n world" the output makes a lot more sense to me than printf "hello \r world"

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

What I think is happening is that \n should be used instead of \r, only reason why I say this is because on my linux terminal when I run printf "hello \n world" the output makes a lot more sense to me than printf "hello \r world"

The RFC disagrees with you.

Lines have to be terminated with \r\n for SMTP.

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

Why aren't you simply using the SMTP mailer directly? If you're just using the sendmail command on the docker AFAICS it's just using SMTP itself and it is not in itself a mailer daemon.

ben-kenney

ben-kenney commented on Dec 19, 2021

@ben-kenney
Author

I started off with SMTP but got autehntication failures. sendmail works for me from the command line and comes close to working
for me with gitea except I don't see the message body.

zeripath

zeripath commented on Dec 19, 2021

@zeripath
Contributor

Well it appears your chosen sendmail command doesn't appear to obey the standard. You could try catting a crlf'd message to it to prove that's the problem. If it is then you might have to write a script that will strip out the CRs or...

Given your sendmail command is not doing anything different from what gitea can do I think you should work out why you were getting authentication problems with the SMTP backend or at least give us some more information as to what kind of authentication problems you were getting

13 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detail

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @zeripath@ben-kenney@wxiaoguang@jprjr

      Issue actions

        Missing email body when using sendmail · Issue #18024 · go-gitea/gitea