mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
8.9k stars 1.17k forks source link

Emails going to spam because of improper header anonimization #2209

Closed UnleashedHost closed 5 years ago

UnleashedHost commented 5 years ago

Hello.

I have set up MailCow according to the official set up docs. My issue is that even though I have proper rDNS, SFP, DKIM and DMARC set up with all green checkmarks in the DNS test on MailCow them emails go to spam. Our domain isn't blacklisted on any of the lists.

The only issue I see there is that the emails are being sent out with multiple "Received from" headers. This is my whole message:

Delivered-To: rozman.nik@gmail.com
Received: by 2002:ab3:6146:0:0:0:0:0 with SMTP id q6csp6550281ltd;
        Mon, 21 Jan 2019 09:02:22 -0800 (PST)
X-Google-Smtp-Source: ALg8bN5QBv5CKedMqcgilX42O/7guF5qeN3UtbpPcaPA7MHRhWPv+6dVodK3KEO+ns0t4Qm1YDLe
X-Received: by 2002:a1c:b14:: with SMTP id 20mr197015wml.103.1548090142774;
        Mon, 21 Jan 2019 09:02:22 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1548090142; cv=pass;
        d=google.com; s=arc-20160816;
        b=QR4gz5opse/oI+o2WZZMiDrNfswFaT91i+dkdJskYBJqlyaviqGDL8y9ESvzqR8kkZ
         j2ZZAjKn8EMxQjkCdz2nih03a2S7ys3VYcRrEj9FQBhUxHpNTuWoXIkx8q89TASH+JUz
         faQgJLFncZ2sgZ6U8C2i3PuF86YdLPaYwTCb3EMBCAIHgseYgWU93DFETkkDPT6IBJeE
         5XNY4m4BzIkS/oEAFKAcg5lf5oIDy5EJw/pf9f0Nn6ArSnhFfaqDw758NyCxUEEtKA+5
         3pCS02K0332lhybQpywg908dR/ty+1muszo30k+HUckDZP6tm0koiGX7G+V63q3uXrgu
         tv4Q==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=from:message-id:subject:date:mime-version:to:dkim-signature;
        bh=e0EE1H0hda125dKPwN9zfT4nmWdeqGEsJSiXXqare68=;
        b=tZtTcpbIU1Bhsm/uZHhfhr33ZK5WqWKAZcPoUukq9KEMUcEVmxTd4PD7I+xFQzQ2Ww
         c0ShdTgGoG3X9g52eqZFGoVAAzjHFoddmwtZ+r2InJDPpDx0cXgRIaoGWyA2Q8Uywi6u
         +0HUYAv6MtgyCMTBlTlJeTRuGbYha5gxIjK8pLQnOOugxOXwY8qZTjYK8nLVrgcwA/2/
         GUmuKoG0nDNb21NhLXmlbCoyzq8/Cf5UCS/LlzkbzCE0ySSik9jysq6Dwr6yfMYZx4iX
         DBcquYjGOIxCa8x/U6SThlaPUzrSRFZ0OYqVuVG2GtOdulC3U/GHnlR9RVx22/1qhRP8
         2omg==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@accuratenode.com header.s=dkim header.b=HTSLkhTh;
       arc=pass (i=1);
       spf=pass (google.com: domain of nick@accuratenode.com designates 116.202.16.225 as permitted sender) smtp.mailfrom=nick@accuratenode.com;
       dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accuratenode.com
Return-Path: <nick@accuratenode.com>
Received: from accuratenode.com (mail.accuratenode.com. [116.202.16.225])
        by mx.google.com with ESMTPS id l9si32926975wro.436.2019.01.21.09.02.22
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Mon, 21 Jan 2019 09:02:22 -0800 (PST)
Received-SPF: pass (google.com: domain of nick@accuratenode.com designates 116.202.16.225 as permitted sender) client-ip=116.202.16.225;
Authentication-Results: mx.google.com;
       dkim=pass header.i=@accuratenode.com header.s=dkim header.b=HTSLkhTh;
       arc=pass (i=1);
       spf=pass (google.com: domain of nick@accuratenode.com designates 116.202.16.225 as permitted sender) smtp.mailfrom=nick@accuratenode.com;
       dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accuratenode.com
Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: nick@accuratenode.com) by accuratenode.com (Postcow) with ESMTPA id 2A71982F66; Mon, 21 Jan 2019 18:02:22 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=accuratenode.com; s=dkim; t=1548090142; h=from:from:sender:reply-to:subject:subject:date:date:
     message-id:message-id:to:to:cc:mime-version:mime-version:
     content-type:content-type:content-transfer-encoding:in-reply-to:
     references; bh=e0EE1H0hda125dKPwN9zfT4nmWdeqGEsJSiXXqare68=; b=HTSLkhTh9B9Bbm/7ZiF2sNg9Rcyzl/ZYkZ8YNzKaz3+lyMOOp7O7Xv6o6cVK+jarSLyk3Y 7sNMHTaJkyiAYZ5VpivkasXLASyRxRBOaNQWOuN2TmmuNUzkxdN3HldVtAplCBDSbFJqaa iFNGvpDh/UhEt1t47ogYc6hCc9HaTegdmynWfM+ejjyHk5fHpLQm64d5JHtLdtYLDP6ZQk mduQnqj5bRfSgmMU9SFtDG5ddI75aIYg0dgBYQDeMYfHROeAV9ZMOtFAyQwor4/UJpPRiu 1DuRQc8v0WQ7zfwXYNeKir4OqEMMn47mwWDYhRWcoNX5gD6IwaId0iQYYVJm+g==
Content-Type: multipart/alternative; boundary="----=_=-_OpenGroupware_org_NGMime-63-1548090141.974293-6------"
To: respect.comrad.ot@gmail.com, rozman.nik@gmail.com
MIME-Version: 1.0
Date: Mon, 21 Jan 2019 18:02:21 +0100
Subject: test
Message-ID: <3f-5c45fb00-b-534e2900@170800349>
From: "Nick | AccurateNode" <nick@accuratenode.com>
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=accuratenode.com; s=dkim; t=1548090142; h=from:from:sender:reply-to:subject:subject:date:date:
     message-id:message-id:to:to:cc:mime-version:mime-version:
     content-type:content-type:content-transfer-encoding:in-reply-to:
     references; bh=e0EE1H0hda125dKPwN9zfT4nmWdeqGEsJSiXXqare68=; b=ngOPXFc1iUj+j/ShRXlJmpA8QiVqtG/M2EbYwq0Tw5v9R1VJRbbGWoL3mrH6V7R8KUxkSa tTpESapQzHXv2MG1HIqPC2dBQcoGzb+ExWxNi56i/TC+Fycho6rf1BakNupwd0yieRByxY 45ZYMXm643OLVfNop2J/LVHjK5kSIT4u7EOWwH7B7MBN3lotYLTZv6Sy/ih83y9UcIZ+xG UVQGh7oZBirVXOaQEoXauePVdATqJj6dAZUG0i8lw+zhyfkwk6p8z/9609s9C0uHUTPUN+ 628GqUn5ThGS8auiLc2B+FD9XKCwfNHY9a0O6B2l1fk4Bvp0xhJKNJbK39RbRQ==
ARC-Seal: i=1; s=dkim; d=accuratenode.com; t=1548090142; a=rsa-sha256; cv=none; b=s8ZZq1wEsl4DTQYby9y4x0/M7d0aztYJDoKAze2TTJr8IzZtE2s3yeOtV59C304+ISpYbn q8IMt4ea1+skNmf5KfMUtdJlih3U9gBX82BxqK5Xamc26VkUPLWf2+pXx81lwuNGmJ39bp uS0jJqyqrx+rIs0RzZvSTvS9e6tmmUWjWmuidQOhqAgFNbflDAl9hs4RWhDb35ArlM//CV +K25h+3U+kTPYnwJVhP0ll6Tn996wW0W7QhIWZsx772cPjp5YI/L8qAroOAx0XQ/neR8EH aSpi23kgl7D8G+J+I12c3QbjqfzM5DkZHmrhZOuJOOkEAdsytHspMv4ek1+N3A==
ARC-Authentication-Results: i=1; accuratenode.com; auth=pass smtp.auth=nick@accuratenode.com smtp.mailfrom=nick@accuratenode.com

------=_=-_OpenGroupware_org_NGMime-63-1548090141.974293-6------
Content-Type: text/plain; charset=utf-8
Content-Length: 5

test

------=_=-_OpenGroupware_org_NGMime-63-1548090141.974293-6------
Content-Type: text/html; charset=utf-8
Content-Length: 17

<html>test</html>

------=_=-_OpenGroupware_org_NGMime-63-1548090141.974293-6--------

I have also tried configuring PostFix to use my custom config after trying your fix from another thread.

The link to the official one that I tried is: click me

I have additionally restarted those instances after each change and made sure I updated the containers. This seems to be occuring on the latest versions of it though as another install on another identical machine on the same network (different IP of course) works just fine. That one however was deployed 3 months ago.

Both servers are running on their own networks (same datacenter, different rack) the only difference between them is that one is running on Ubuntu 16.04.1 LTS and the other one on Debian 9.

Other than that I have tried editing the /etc/hosts file to see if that changed anything at all, but no change.

If you have a possible fix for this please let me know as soon as possible as we are unable to send out emails without them going to spam.

I am willing to provide credentials so you can see the situation for yourself.

Kind regards, Nick

Braintelligence commented 5 years ago

The thing is that specific mail hosters won't ever accept mails from fresh mail server IPs they've never seen before as anything but spam. This goes for example for microsofts mail servers.

Their users will have to proactively mark the mails as not-spam. At some point your mails will not be automatically flagged as spam then.

UnleashedHost commented 5 years ago

In my defense that same server has already been used to send out emails before with the same exact IP. We have reinstalled everything on it (even the OS) because we wanted to have a clean sheet. The reason for reinstallation was that we were switching to a different OS and because of a domain update.

Besides that the other server never sent to spam just minutes after its initial installation.

Braintelligence commented 5 years ago

Then maybe this is related: https://stackoverflow.com/questions/38420148/multiple-received-from-in-headers-while-sending-email-with-postfix

Multiple received from headers and also gmail.

UnleashedHost commented 5 years ago

Yeah. This is the exact one I've looked at before, but the issue isn't fixed.

Braintelligence commented 5 years ago

Let's wait for a member to look at this. If the multiple received-froms are the problem I sadly don't know which knob to turn to help you out ☹️.

UnleashedHost commented 5 years ago

Yeah. Thank you for your help anyways.

andryyy commented 5 years ago

Multiple Received headers are not a problem and quite normal.

Not being on a blacklist does not indicate you will land in any inbox. Outlook and Gmail hate new domains or old domains with new IPs. They will punish them 100 times and at some point accept them as ham.

116.202.16.225 seems to be a Hetzner IP. Their reputation isn't the best to begin with (Hetzner does an amazing job looking at their size!). Again: I don't mean blacklistings, your IP may never have seen a blacklist, it still belongs to a given ASN. Just like OVH. No matter the IP, you are doomed on 16276.

As long as you submit over your mail server and not directly communicate with Gmails MTA, you will have at least 2 hops (you -> your mta -> their mta). That's totally fine. More hops are not a problem, too.

UnleashedHost commented 5 years ago

I have another mail server running just a slightly older MailCow set up. Same scenario as this one. That one however doesn't send multiple headers. That one doesn't send the header on 127.0.0.1.

I've never had issues with that one even though it's on Hetzner as well. The IPs were updated on that one multiple times in a few months due to switching from one provider to another. I think I'll stick with Hetzner for now.

Any chance you could point me towards how to properly filter it or try to replicate it for yourself as I believe it is an actual bug and not just an issue that I might be having with it cause of the IPs.

andryyy commented 5 years ago

As long as you submit over port 587, you will always be the first hop, your MTA is the next hop, next/final is Gmail (for example) as "received by".

It is possible we replaced ALL headers previously, which was stupid. It does not change anything about the fact, that multiple received from headers are normal and don't get you into spam.

The 127.0.0.1 "received from" header does not indicate spam or something. Google does not punish that. This is a common first hop.

andryyy commented 5 years ago

Triggering @mkuron - you see a problem here?

mkuron commented 5 years ago

The multiple Received headers definitely isn't a problem. DKIM etc. validates correctly, so there is nothing you can do.

In my experience, Gmail isn't too bad in terms of deliverability -- unlike Microsoft, they don't just block everyone they don't know.

I suspect you just need to wait a bit until Google picks up that you aren't malicious. Send actual messages to Gmail users and have them manually move them out of spam. Sending messages containing just "test" doesn't help there because the filter looks at the message contents too. Also, check Google Postmaster Tools to see if that reports any specific problem.

UnleashedHost commented 5 years ago

Hello.

Thank you for replying. I am enforcing TLS on all in/out mail so I don't think that would be an issue. I'll try to do that. I have already registered on postmaster.google.com (i think its the correct domain?) and there is no indication of anything being wrong there.

I'll try to take into consideration your suggestion. Surely I can just plop Mailcow on some other server and it should work just fine or is there anything else that I'd have to do GMail wise like reporting an IP change or anything else that might limit me in the future ?

mkuron commented 5 years ago

Switch off TLS enforcement, just in case. Google supports TLS, but who knows what side effects it has. Also, check if you have any modifications in git: git diff origin/master. Try to keep your Mailcow as standard as possible while investigating this.

UnleashedHost commented 5 years ago

Alright. Will do.

UnleashedHost commented 5 years ago

This is the full diff:

diff --git a/data/conf/nginx/site.conf b/data/conf/nginx/site.conf
index 67d6f1a1..4ba05b19 100644
--- a/data/conf/nginx/site.conf
+++ b/data/conf/nginx/site.conf
@@ -17,6 +17,27 @@ map $sent_http_content_type $expires {
 }

 server {
+  listen 80;
+  listen [::]:80;
+  server_name autoconfig.*;
+  root /web;
+  location / {
+    fastcgi_split_path_info ^(.+\.php)(/.+)$;
+    fastcgi_pass phpfpm:9002;
+    include /etc/nginx/fastcgi_params;
+    fastcgi_param SCRIPT_FILENAME $document_root/autoconfig.php;
+    try_files /autoconfig.php =404;
+  }
+}
+server {
+  listen 80 default_server;
+  listen [::]:80 default_server;
+  include /etc/nginx/conf.d/server_name.active;
+  if ( $request_uri ~* "%0A|%0D" ) { return 403; }
+  return 301 https://$host$uri$is_args$args;
+}
+
+server {
   include /etc/nginx/mime.types;
   charset utf-8;
   override_charset on;
diff --git a/data/conf/postfix/anonymize_headers.pcre b/data/conf/postfix/anonymize_headers.pcre
index 099094d9..48cf4bdb 100644
--- a/data/conf/postfix/anonymize_headers.pcre
+++ b/data/conf/postfix/anonymize_headers.pcre
@@ -1,7 +1,6 @@
-if /^\s*Received:.*Authenticated sender.*\(Postcow\)/
 /^\s*Received:.*Authenticated sender:(.+)/
-  REPLACE Received: from localhost (localhost [127.0.0.1]) (Authenticated sender:$1
-endif
+    REPLACE Received: from localhost (localhost [127.0.0.1]) (Authenticated sender:$1
+/^\s*User-Agent/        IGNORE
 /^\s*X-Enigmail/        IGNORE
 /^\s*X-Mailer/          IGNORE
 /^\s*X-Originating-IP/  IGNORE
diff --git a/data/conf/postfix/main.cf b/data/conf/postfix/main.cf
index 83a252d8..6c649b27 100644
--- a/data/conf/postfix/main.cf
+++ b/data/conf/postfix/main.cf
@@ -132,7 +132,8 @@ smtp_sasl_password_maps = proxy:mysql:/opt/postfix/conf/sql/mysql_sasl_passwd_ma
 smtp_sasl_security_options =
 smtp_sasl_mechanism_filter = plain, login
 smtp_tls_policy_maps=proxy:mysql:/opt/postfix/conf/sql/mysql_tls_policy_override_maps.cf
mkuron commented 5 years ago

I‘m pretty sure there is more. Push the d key to scroll down in the diff.

-if /^\s*Received:.*Authenticated sender.*\(Postcow\)/

That‘s a bad idea as it breaks DKIM signatures on incoming emails. It‘s not what‘s causing your Gmail problem, but you‘ll want to revert this change.

Lajpat29 commented 5 years ago

Top mailbox providers(Google and Microsoft etc) blocks some of ASN based on their past spam history so, if even though ip is not on any blacklist, still email delivery fail due to such restrictions. I would suggest third party smtp relay like amazonses, mailgun and sendgrid etc for relay purpose as then you don't have to worry about ip blacklisting. But this workaround has drawbacks like loss of email privacy as now you are using third party server for relay. Mailgun provide option of using third party relay it can be easily configured from mailcow ui and then attach it to domain.

andryyy commented 5 years ago

That's right. IP blacklists are the worst thing to happen, but at least you can check against most of them. But you cannot check how some providers score your ASN. Large ISPs will also have their own DNSBL.

mkuron commented 5 years ago

You can also use Mailcow's transport maps (on the Routing tab) to only relay certain destinations via an external email provider. I use that to relay messages to outlook.com and hotmail.com via Sendgrid because Microsoft seems to effectively have a whitelist of IP addresses from which they accept messages. Sending to most other destinations should be fine as long as your server is on a reasonably reputable ASN.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.