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

allmailfrom setting not having the desire effect #72

Open
paulgit opened this issue Apr 8, 2020 · 10 comments
Open

allmailfrom setting not having the desire effect #72

paulgit opened this issue Apr 8, 2020 · 10 comments

Comments

@paulgit
Copy link

paulgit commented Apr 8, 2020

I want all the emails that Nullmailer sends to come from email address new@xxxx.xx so I set this address in my allmailfrom file. The SMTP relay host I am using expects email from this address, but when I send a test message then there is a bounce in the log file and then it's moved to the failed folder, look at the file the first line implies the re-write has worked but the actual from address in the email is still the old one:

new@xxxx.xx
paul@xxxx.xx

Received: (nullmailer pid 944 invoked by uid 0);
  Wed, 08 Apr 2020 13:33:05 -0000
To: paul@xxxx.xx
Subject: Test Email
From: old@xxxx.xx
Date: Wed, 08 Apr 2020 14:33:05 +0100
Message-Id: <1586352785.655229.943.nullmailer@xxxx.xx.xxxx.xx>

This is occurring on Nullmailer 2.2 as distributed with Debian 10.

Is there perhaps another setting I need?

@berezovskyi
Copy link

I am having a similar problem. I realised that envelope sender change as discussed in #13 and #55 will not do much good if the provider strictly checks username==sender==from, as Migadu does:

554 5.7.1 From header does not match envelope sender.

I am still not sure what the sendmail-bin wrapped mentioned by @jahir in #55 means, but seems like it could be a real solution.

@mehov
Copy link

mehov commented Aug 11, 2020

Unfortunately, allmailfrom seems to add return path only, and I'm still getting:

smtp: Failed: 550 5.7.0 Sender or From header address rejected: not owned by authorized user

Setting the global

NULLMAILER_HOST=example.com
NULLMAILER_USER=sender

in /etc/environment helps with direct sendmail "recipient@example.com" calls, but has no effect on the cron mail.

A wrapper script has technically worked, but my SMTP still rejected with Message rejected under suspicion of SPAM, so not an option either.

Found this dma mention which seems like it could be an alternative and will have to look into it.

@henning-schild
Copy link

It is an issue that deserves fixing directly here, not with a wrapper. Having control over "From" and "Sender" is often needed. Not sure it should be done via allmailfrom or another mechanism to stay compatible to older versions of nullmailer.

But honestly allmailfrom not actually touch the From: is all but intuitive ;)

@lkraav
Copy link

lkraav commented Jan 2, 2022

But honestly allmailfrom not actually touch the From: is all but intuitive ;)

Yeah, allmailsender would perhaps be more accurate.

@adippl
Copy link

adippl commented Jan 8, 2022

allmailfrom seems to affect From: line in logs, but doesn't affect actual mail.
I guess It could be a bug.

I've tried to check how how allmailfrom works and modify it, but I couldn't figure it out.
I've created small hack for sendmail which works like -f flag but loads From: from a file.
It could be more reliable and easier solution than enviroment variables.

It works with nullmailer's sendmail and mail from mailutils.
I had issue with cronie (cron). Cron mails somehow retain their original From: field.
I still had to change MAILFROM variable in cron config file to set proper From:

Filepath is hardcoded because I'm not familiar with automake/autoconf generated variables.
It's c style code because that's what I'm more familiar with.

diff --git a/src/sendmail.cc b/src/sendmail.cc
index 534ad39..3a81845 100644
--- a/src/sendmail.cc
+++ b/src/sendmail.cc
@@ -29,6 +29,7 @@
 #include "forkexec.h"
 #include "setenv.h"
 #include "cli++/cli++.h"
+#include "stdio.h"
 
 const char* cli_program = "sendmail";
 const char* cli_help_prefix = "Nullmailer sendmail emulator\n";
@@ -100,6 +101,32 @@ bool setenvelope(char* str)
   return true;
 }
 
+bool force_From()
+{
+	char* str = NULL;
+	FILE* f = NULL;
+	char fpath[]{"/etc/nullmailer/forced_from"};
+	size_t strSize = -1;
+	ssize_t gl_ret = 0;
+	if(access(fpath, F_OK)==0){
+		f = fopen( fpath, "r");
+		gl_ret = getline(&str, &strSize, f);
+		if( gl_ret == -1 ) {
+			free(str);
+			fclose(f);
+			return false;
+		}
+		fclose(f);
+		// cut off the last character if it's newline
+		if ( str[gl_ret-1] == '\n' )
+			str[gl_ret-1] = '\0';
+		setenvelope(str);
+		free(str);
+		return true;
+	}
+	return false;
+}
+
 int do_exec(const char* program, const char* args[])
 {
   mystring path = program_path(program);
@@ -136,6 +163,8 @@ int cli_main(int argc, char* argv[])
         extra_args[extra_argc++] = o_from;
       }
     }
+    if(!o_from)
+      force_From();
 
     for(int i = 0; i < argc; i++)
       extra_args[extra_argc++] = argv[i];

@jarthod
Copy link

jarthod commented Apr 14, 2022

I just encountered this problem too when trying to use nullmailer with a custom From. Is there any other way (than modifying the source code) to achieve this? do we know if it's a bug or not? or shall I just use another service?

@adippl
Copy link

adippl commented May 26, 2022

I think I have figured it out.
Some programs like cronie cron daemon generate mail files with their own From:
Right now allmailfrom cannot overwrite From: line which already exist in mail file piped into sendmail.
It sometimes sets only Return-Path: because this header field was not already set in mail file generated by crond.

I have created a patch which replaces From: if allmailfrom is configured.
This is example of a cron mail with correctly working allmailfrom
user and hostname are replaced, but original name of the sender is unchanged.

X-Cron-Env: <HOME=/>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Date: Thu, 26 May 2022 15:45:01 +0200
Message-Id: <1653572701.537208.8045.nullmailer@REMOVED>
From: CronDaemon <allmailfrom@fake.email>
X-TUID: Pb8F2z6y9nw3

I have created a pull request with my fix. #84

@gnugnug
Copy link

gnugnug commented Jul 11, 2023

Unfortunately setting NULLMAILER_USER and NULLMAILER_HOST doesn't help when the program that creates the email already sets a sender address. mail -r foo@bar.tld <recipient> will still create an email with the header "From: foo@bar.tld" even with NULLMAILER_USER and NULLMAILER_HOST set.

nullmailer-inject has the flag "f", which: "Ignore and remove any From header lines and always insert a generated one"
Nuking the original From header (which we don't want) would theoretically fix the problem, unfortunately nullmailer-inject runs before the return path address is replaced by the value from /etc/nullmailer/allmailfrom.

As a workaround we can use a wrapper script as suggested in this thread and in https://www.atwillys.de/content/linux/force-nullmailer-to-use-a-fixed-from-address/:

  1. Move /usr/sbin/sendmail to /usr/sbin/sendmail-bin
  2. Create a wrapper script at /usr/sbin/sendmail and make it executable:
#!/bin/bash
/usr/sbin/sendmail-bin "$@" -f "$(cat /etc/nullmailer/allmailfrom)" </dev/stdin

This will append the address from /etc/nullmailer/allmailfrom as a sender address to every sendmail call. After this the "f" flag will kick in, remove the original from header and all occurences of the original from address will be gone. Now every script on your system can create emails with whatever from addresses it wants, as those addresses will all be overwritten. You only have to make sure to always have NULLMAILER_FLAGS=f set. Add NULLMAILER_FLAGS=f to /etc/environment (for PAM aware logins) and export NULLMAILER_FLAGS=f to /etc/profile.d/nullmailer.sh (for Bash).

@kyrofa
Copy link

kyrofa commented Oct 26, 2023

Well, darn, just hit this on Debian 12 (Bookworm). I quickly fell in love with the simplicity of nullmailer, but my SMTP server (postmark) is pretty strict about the email address in the From line. I need it to be a specific one.

@LaXiS96
Copy link

LaXiS96 commented Mar 27, 2024

Same here, Zoho bounces email with 553 Relaying disallowed as MAILER-DAEMON@myhost.mydomain when sending a test email with echo test | mail user@domain.tld, ignoring the value of allmailfrom.
I was previously using msmtp as a sendmail-compatible MTA but it doesn't queue failed messages, so it isn't a good match for e.g. cron mail. Looks like nullmailer can't help me either...

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

10 participants