Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cron mail is rejected due to missing domain #75

Open
varac opened this issue Feb 5, 2020 · 25 comments
Open

Cron mail is rejected due to missing domain #75

varac opened this issue Feb 5, 2020 · 25 comments

Comments

@varac
Copy link

varac commented Feb 5, 2020

I'm using this configuration:

root@brix:/etc/dma# grep -vE '(^$|^#)' dma.conf
SMARTHOST localhost
MAILNAME /etc/mailname
MASQUERADE [email protected]

to send all mails to a docker container running an smtp replay which accepts mail on port 25 and forwards it to
a mail hub using smtp auth.

I can send mail fine using the mail command like this:

echo hi | mail root

But cronmail is rejected because the From: header is root (Cron Daemon) without any domain.
My smtp relay rejects it with these message:

H=(brix.MY.DOMAIN) [172.17.0.1] F=<[email protected]> rejected after DATA: header syntax (unqualified address not permitted: failing address in "From:" header is: roo

t (Cron Daemon)): unqualified address not permitted: failing address in "From:" header is: root (Cron Daemon)

Shortly after that, a bounce notification is also rejected:

H=(brix.MY.DOMAIN) [172.17.0.1] F=<> rejected after DATA: header syntax (missing or malformed local part: failing address in "From:" header is: MAILER-DAEMON <>): missing or malformed local part: failing address in "From:" header is: MAILER-DAEMON <>

And i end up having 2 mails in the /var/spool/dma/ spool directory:

root@brix:/etc# cat /var/spool/dma/M22152e.55d8f3dcc2f0
Received: from MAILER-DAEMON
        id 22152e
        by brix.MY.DOMAIN (DragonFly Mail Agent v0.11);
        Wed, 05 Feb 2020 13:46:02 +0100
X-Original-To: <[email protected]>
From: MAILER-DAEMON <>
To: [email protected]
Subject: Mail delivery failed
Message-Id: <[email protected]>
Date: Wed, 05 Feb 2020 13:46:02 +0100

This is the DragonFly Mail Agent v0.11 at brix.MY.DOMAIN.

There was an error delivering your mail to <[email protected]>.

localhost [::1] did not like our final DATA:
550 header syntax

Message headers follow.

Received: from root (uid 0)
        (envelope-from [email protected])
        id 22152a
        by brix.MY.DOMAIN (DragonFly Mail Agent v0.11);
        Wed, 05 Feb 2020 13:46:01 +0100
From: root (Cron Daemon)
To: root
Subject: Cron <root@brix> fhkqrjhfb
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Date: Wed, 05 Feb 2020 13:46:01 +0100
Message-Id: <[email protected]>
root@brix:/etc# cat /var/spool/dma/Q22152e.55d8f3dcc2f0
ID: 22152e.55d8f3dcc2f0
Sender:
Recipient: [email protected]

What am I doing wrong ? Unfortunatly you can't configure the From address for cron mails, so there's nothing I can do about this on cron's side.

@varac
Copy link
Author

varac commented Feb 5, 2020

I also saw Make MASQUERADE config setting override -f
and tried latest master, but if I understand correctly, MASQUERADE only sets the envelope from, not the from header right ?

@corecode
Copy link
Owner

corecode commented Feb 5, 2020

That is correct, we don't rewrite header lines. You probably should configure your smarthost not to reject mails originating from your machines/cron.

@varac
Copy link
Author

varac commented Feb 5, 2020

But what happens when delivering directly to an smtp server which is not under my control ? I.e. the one from my mail provider ?
I think it would be a great feature to append the MAILNAME to any from address without a specific domain. This would solve this issue out of the box.

@varac
Copy link
Author

varac commented Feb 5, 2020

If I'm not mistaken this is basically the discussion held in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=697871, or am I wrong ?

@corecode
Copy link
Owner

corecode commented Feb 5, 2020 via email

@varac
Copy link
Author

varac commented Feb 5, 2020

would you like to submit a PR for review?

I would, but I can't since I haven't written a single line of C in my whole life!

@varac
Copy link
Author

varac commented Feb 5, 2020

But I'm happy to test any PR and give feedback.

@vlyon
Copy link

vlyon commented Feb 7, 2020

If I'm not mistaken this is basically the discussion held in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=697871, or am I wrong ?

Actually this is discussed here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=830518, but is related to the one you mentioned. That bug has been partially fixed, but the unqualified To: and From: headers are not being corrected.

@vlyon
Copy link

vlyon commented Feb 7, 2020

See related issue #21

@varac
Copy link
Author

varac commented Feb 7, 2020

Actually this is discussed here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=830518

@vlyon Thanks for the correct link, this debian bug report describes my issue pretty well.

@varac
Copy link
Author

varac commented Feb 12, 2020

@corecode Is there any chance to get this fixed soon ? Without this I need to look for another alternative, since recieving system/cron-mails is pretty important for me.

@corecode
Copy link
Owner

corecode commented Feb 12, 2020 via email

@trevor87
Copy link

trevor87 commented Sep 4, 2020

@corecode Is there any chance to get this fixed soon ? Without this I need to look for another alternative, since recieving system/cron-mails is pretty important for me.

Did you find a solution to this? I am also having trouble to get DMA to work with anything else than gmail (e.g. gmx.net does not work).

@vlyon
Copy link

vlyon commented Sep 7, 2020

I have found a workaround for this issue, and have been using it for some time now on Debian.

I use a simple perl script that I've written, to send email from cron via DMA.

In my crontab I have the following line:
SHELL=/home/somewhere/bin/cronsh

Then the cronsh script contains:

#!/usr/bin/perl -CA
use 5.024;
use warnings;
use IPC::Run3;
use Email::Stuffer;

@ARGV == 2 and $ARGV[0] eq '-c' or die "Usage:\n$0 -c <command>\n";
my $out;
run3 $ARGV[1], undef, \$out, \$out, {return_if_system_error => 1};
if ($? or length $out) {
    utf8::decode $out;
    $out .= $! if $?;
    $out = Email::Stuffer
    ->from("Cron <$ENV{LOGNAME}\@myhostname.com>")
    ->to('"Vernon Lyon" <[email protected]>')
    ->subject($ARGV[1])
    ->text_body($out, encoding => '8bit')
    ->as_string;
    run3 [qw(/usr/sbin/dma -it)], \$out;
}

@jjakob
Copy link
Contributor

jjakob commented Apr 12, 2021

I've added header From rewriting to dma. I'll open a PR.

@corecode
Copy link
Owner

corecode commented Apr 12, 2021 via email

@jjakob
Copy link
Contributor

jjakob commented Apr 14, 2021

#96

@HenriGEIST
Copy link

If it can help I had the same problem and I have solved it by applying this diff against tag 'v0.13'

`
$ git diff
diff --git a/mail.c b/mail.c
index bf82d52..c0caae8 100644
--- a/mail.c
+++ b/mail.c
@@ -397,7 +397,9 @@ readmail(struct queue *queue, int nodot, int recp_from_header)
* Ignore a leading RFC-976 From_ or >From_ line mistakenly
* inserted by some programs.
*/

  •                   if (strprefixcmp(line, "From ") == 0 || strprefixcmp(line, ">From ") == 0)
    
  •                   if (strprefixcmp(line, "From ")                    == 0 ||
    
  •                       strprefixcmp(line, ">From ")                   == 0 ||
    
  •                       strprefixcmp(line, "From: root (Cron Daemon)") == 0)
                              continue;
                      had_first_line = 1;
              }
    

`

It simply reject the first
From: root (Cron Daemon)
As invalid just like firsts "From " and ">From ".
And in fact this is not a valid expeditor (At least in my point of view)

HenriGEIST added a commit to HenriGEIST/dma that referenced this issue Sep 6, 2024
Drop the anyway malformed "From: root (Cron Daemon)"
That cron daemon place by default at head of its messages.

Just like mistakenly inserted RFC-976 "From_" or ">From_" are already
dropped.

When not removed, lot of modern mail delivery service will reject or
silently drop the message.

Only some very new version of cron can change this behavior and it is
not the default.
On old version there is nothing you can do.

When removed the expediter is available anyway by the mail envelop.
Then no meaningful information is lost.
@corecode
Copy link
Owner

corecode commented Sep 6, 2024

From: root (Cron Daemon) is not invalid. The receiving mail server is configured to reject it.

@HenriGEIST
Copy link

OK may be not strictly speaking "invalid" by RFC criteria.
But wired, and rejected by all 3 smarthosts I have tried :

  • "smtp.gmail.com";
  • "mail.gandi.net";
  • "smtp.laposte.net".

If most mail provider reject it, for my usage it is the same as "invalid".

I will keep the workaround on my fork as long as I have no better solution to get my cron report to find their way to my mailbox.
If it help someone else that's good. If not there is no harm.

@corecode
Copy link
Owner

corecode commented Sep 6, 2024 via email

@HenriGEIST
Copy link

HenriGEIST commented Sep 6, 2024

I am not sure what you mean by "authenticate" but I always use login and password on the SMTP before sending a mail.
If I don't nothing goes by what ever I do with the "From:" line in the mail content.

My /etc/dma/dma.conf contain :

`
SMARTHOST mail.gandi.net

PORT 465

ALIASES /etc/aliases

AUTHPATH /etc/dma/auth.conf

SECURETRANSFER

MAILNAME /etc/mailname

MASQUERADE [email protected]
`

And my /etc/dma/auth.conf contain :

[email protected]|mail.gandi.net:WWWWWW

Everything work well with the patch and fail silently without it.
No error message, /var/log/mail.log say "[email protected] delivery successful"
Just without the patch the mail never reach destination.

@corecode
Copy link
Owner

corecode commented Sep 6, 2024 via email

@HenriGEIST
Copy link

Maybe but exact same situation with 'smtp.laposte.net'.

@HenriGEIST
Copy link

But in fact I do not now where exactly it is discarded.
Could be any intermediary server between the first smart host and the final pop/imap delivery server.
Could be an anti spam anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants