Page 1 of 1

Spamassassin marks mail as spam

Posted: Tue Jul 06, 2021 7:52 pm
by MadMcJack
I am using Opencart 3.0.3.7 and when emails are being sent to customers using spamassassin they are flagged as follows:

Symbol: SUBJ_EXCESS_BASE64(1.50)
Symbol: FROM_EXCESS_BASE64(1.50)
Symbol: MIME_BASE64_TEXT_BOGUS(1.00)
Symbol: MIME_BASE64_TEXT(0.10)
Symbol: CTYPE_MIXED_BOGUS(1.00)
Symbol: R_PARTS_DIFFER(0.37)
Symbol: MISSING_MID(2.50)

We are doing nothing fancy and these scores seem to indicate basic mail headers.

The MISSING_MID(2.50) indicates a missing Message-ID header for instance.
https://stackoverflow.com/questions/144 ... ent-by-php

There also seem to be problems with the base64_encoded parts in To, From, Reply To and Subject?

Re: Spamassassin marks mail as spam

Posted: Tue Jul 06, 2021 8:33 pm
by ADD Creative
Your mail server should be adding the Message-ID if it's not there. You might want to check its settings. Base64 scores also look high.

I believe this has been reported before.
https://github.com/opencart/opencart/pull/7440

Re: Spamassassin marks mail as spam

Posted: Tue Jul 06, 2021 9:50 pm
by MadMcJack
Thanks. It looks like the exact issue I was having.

I am not in control of the mail server so I have asked them to check why the message-id is not being set.

As for the utf8_encode parts... Spamassassin seems to think that is indicative of somebody trying to be spammer.

Not sure if that is OpenCart's problem (don't think so).

Re: Spamassassin marks mail as spam

Posted: Wed Jul 07, 2021 2:17 am
by ADD Creative
I think it is an OpenCart problem. If spam filters put such a large weight to it being spam then unnecessarily Base64 encoding should be avoided.

The same with the missing Message-ID header. If spam filters give it such a large weight and the addition of a message-id field when none appears is only something a MTA MAY add. Then it would be best for OpenCart to set this.

Have you tried using the "Mail" Mail Engine to see if that adds the Message-ID header?

Re: Spamassassin marks mail as spam

Posted: Wed Jul 07, 2021 4:39 pm
by paulfeakins
ADD Creative wrote:
Wed Jul 07, 2021 2:17 am
I think it is an OpenCart problem. If spam filters put such a large weight to it being spam then unnecessarily Base64 encoding should be avoided.

The same with the missing Message-ID header. If spam filters give it such a large weight and the addition of a message-id field when none appears is only something a MTA MAY add. Then it would be best for OpenCart to set this.

Have you tried using the "Mail" Mail Engine to see if that adds the Message-ID header?
Could be that OpenCart needs to optimise the emails that are sent as it seems that email delivery systems are getting stricter and stricter these days.

Re: Spamassassin marks mail as spam

Posted: Wed Jul 07, 2021 6:55 pm
by JNeuhoff
Could be that OpenCart needs to optimise the emails that are sent as it seems that email delivery systems are getting stricter and stricter these days.
Also, mails using outlook.com, hotmail.com, live.com, or msn.com tend to be more likely to be treated as spam. It's better to use domain-name specific email accounts. Besides, the MS-based services frequently violate the GDPR rules, by automatically sniffing out the actual mail contents for purposes other than a mail delivery.

Re: Spamassassin marks mail as spam

Posted: Wed Jul 07, 2021 8:43 pm
by EvolveWebHosting
Have you tried sending via SMTP and also make sure you have DKIM and SPF Records setup.

Instructions for setting up SPF and DKIM in cPanel (it's simple)
https://core.evolvewebhost.com/knowledg ... entication

Re: Spamassassin marks mail as spam

Posted: Mon Jul 12, 2021 1:28 am
by sjgarth
I send by SMTP, I have DKIM and SPF set up correctly and the problem is OPENCART.
It encodes all emails as base54 and the anti spam measures used by my (and many other) service providers does not allow unnecessary base64 encoding.
This is causing a big problem and OPENCART - not the users or the service providers - need to sort this out.
At the moment I have a shop which doesn't contact the customers.

Re: Spamassassin marks mail as spam

Posted: Tue Jul 13, 2021 1:01 am
by sjgarth
As I posted previously, I use the SMTP option for mail, and have DKIM and SPF setup. As a stop gap to prevent base64 encoding I modified the cart2\system\library\mail\smtp.php file to prevent the encoding.
My service provider was stopping unnecessary base64 encoding as an anti spam measure, but recent emails have not been stopped, therefore I think it is a suitable stop gap until Open Cart fix the issue.
I am not an expert by any means, and I do not know if this will cause problems, however testing has shown that emails continue to be sent without any obvious issues.
My smtp.php file is now (all old code commented out) ;

Code: Select all

<?php
namespace Mail;
class Smtp {
	public $smtp_hostname;
	public $smtp_username;
	public $smtp_password;
	public $smtp_port = 25;
	public $smtp_timeout = 5;
	public $verp = false;

	public function send() {
		if (is_array($this->to)) {
			$to = implode(',', $this->to);
		} else {
			$to = $this->to;
		}

		$boundary = '----=_NextPart_' . md5(time());

		$header  = 'MIME-Version: 1.0' . PHP_EOL;
		$header .= 'To: <' . $to . '>' . PHP_EOL;
		/*$header .= 'Subject: =?UTF-8?B?' . base64_encode($this->subject) . '?=' . PHP_EOL;*/
               /*NEW*/ $header .= 'Subject: ' . $this->subject . ' <' . PHP_EOL;
		$header .= 'Date: ' . date('D, d M Y H:i:s O') . PHP_EOL;
		/*$header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;*/
               /*NEW*/ $header .= 'From: ' . $this->sender . ' <' . $this->from . '>' . PHP_EOL;

		if (!$this->reply_to) {
			/*$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;*/
           /*NEW*/ $header .= 'Reply-To: ' . $this->sender . ' <' . $this->from . '>' . PHP_EOL;
		} else {
			/*$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->reply_to) . ' ' . $this->reply_to . '>' . PHP_EOL;*/
           /*NEW*/ $header .= 'Reply-To: ' . $this->reply_to . ' <' . $this->reply_to . '>' . PHP_EOL;
		}

		$header .= 'Return-Path: ' . $this->from . PHP_EOL;
		$header .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
		$header .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . PHP_EOL . PHP_EOL;

		if (!$this->html) {
			$message  = '--' . $boundary . PHP_EOL;
			$message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
			$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
			$message .= $this->text . PHP_EOL;

	EVERYTHING ELSE AS ORIGINAL
	

Re: Spamassassin marks mail as spam

Posted: Tue Jul 13, 2021 6:02 am
by ADD Creative
There is an example of one way to only encode if necessary (requiring mbstring) here. https://github.com/opencart/opencart/pull/7440/files

Re: Spamassassin marks mail as spam

Posted: Tue Jul 13, 2021 5:15 pm
by by mona
you could just do this:

add a private function to the class system/library/mail/smtp.php

Code: Select all

// return base64 encoded if needed ($item not ASCII)
private function mailb64_if_required ($item) {
	return (!mb_check_encoding($item, 'ASCII') ? '=?UTF-8?B?' . base64_encode($item) . '?=' : $item);
}
then change in that same file the calls of:

Code: Select all

$header .= 'Subject: =?UTF-8?B?' . base64_encode($this->subject) . '?=' . PHP_EOL;
to

Code: Select all

$header .= 'Subject: ' . $this->mailb64_if_required($this->subject) . PHP_EOL;

Code: Select all

$header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
to

Code: Select all

$header .= 'From: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->from . '>' . PHP_EOL;

Code: Select all

$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
to

Code: Select all

$header .= 'Reply-To: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->from . '>' . PHP_EOL;

Code: Select all

$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->reply_to . '>' . PHP_EOL;
to

Code: Select all

$header .= 'Reply-To: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->reply_to . '>' . PHP_EOL;

So you do not have to constantly do:

Code: Select all

if (mb_check_encoding($this->xxxxxx, 'ASCII')) {
} else {
}
keeps it clean.

Re: Spamassassin marks mail as spam

Posted: Thu Mar 03, 2022 12:07 am
by sjgarth
by mona wrote:
Tue Jul 13, 2021 5:15 pm
you could just do this:

add a private function to the class system/library/mail/smtp.php
...
A bit late I know, but i have just used this solution after updating the software.
So far it appears to work, I hope it continues.
Thanks.

Re: Spamassassin marks mail as spam

Posted: Sat Jan 27, 2024 7:47 pm
by rufus.d
This works like a charm to resolve the missing message-id header issues in OC 3.0.3.9 ;D
by mona wrote:
Tue Jul 13, 2021 5:15 pm
you could just do this:

add a private function to the class system/library/mail/smtp.php

Code: Select all

// return base64 encoded if needed ($item not ASCII)
private function mailb64_if_required ($item) {
	return (!mb_check_encoding($item, 'ASCII') ? '=?UTF-8?B?' . base64_encode($item) . '?=' : $item);
}
then change in that same file the calls of:

Code: Select all

$header .= 'Subject: =?UTF-8?B?' . base64_encode($this->subject) . '?=' . PHP_EOL;
to

Code: Select all

$header .= 'Subject: ' . $this->mailb64_if_required($this->subject) . PHP_EOL;

Code: Select all

$header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
to

Code: Select all

$header .= 'From: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->from . '>' . PHP_EOL;

Code: Select all

$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
to

Code: Select all

$header .= 'Reply-To: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->from . '>' . PHP_EOL;

Code: Select all

$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->reply_to . '>' . PHP_EOL;
to

Code: Select all

$header .= 'Reply-To: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->reply_to . '>' . PHP_EOL;

So you do not have to constantly do:

Code: Select all

if (mb_check_encoding($this->xxxxxx, 'ASCII')) {
} else {
}
keeps it clean.

Re: Spamassassin marks mail as spam

Posted: Sat Jan 27, 2024 10:33 pm
by rufus.d
Is there any similar solution for Marketing -> Mails (To send emails to newsletter subscribers). The below modification fixed the issue for all emails, except the one under the marketing. When sent, it's sending without a message-id header and marks as SPAM, which doesn't even reach the user.

Any help would be really appreciated.

Re: Spamassassin marks mail as spam

Posted: Sat Jan 27, 2024 10:59 pm
by ADD Creative
rufus.d wrote:
Sat Jan 27, 2024 10:33 pm
Is there any similar solution for Marketing -> Mails (To send emails to newsletter subscribers). The below modification fixed the issue for all emails, except the one under the marketing. When sent, it's sending without a message-id header and marks as SPAM, which doesn't even reach the user.

Any help would be really appreciated.
That code doesn't add a message-id header. It probably just lowers the spam score. Any decent host should add the message-id header if it's not there. Maybe ask you host about it.

I did link to someone else's change that did add a message-id header.
viewtopic.php?p=866184#p824826

Re: Spamassassin marks mail as spam

Posted: Mon Jan 29, 2024 7:44 pm
by paulfeakins
rufus.d wrote:
Sat Jan 27, 2024 10:33 pm
Is there any similar solution for Marketing -> Mails (To send emails to newsletter subscribers).
I would recommend sending from MailChimp using Clear Thinking's excellent extension.

Re: Spamassassin marks mail as spam

Posted: Fri Apr 05, 2024 4:01 pm
by mandom
by mona wrote:
Tue Jul 13, 2021 5:15 pm
you could just do this:

add a private function to the class system/library/mail/smtp.php

Code: Select all

// return base64 encoded if needed ($item not ASCII)
private function mailb64_if_required ($item) {
	return (!mb_check_encoding($item, 'ASCII') ? '=?UTF-8?B?' . base64_encode($item) . '?=' : $item);
}
then change in that same file the calls of:

Code: Select all

$header .= 'Subject: =?UTF-8?B?' . base64_encode($this->subject) . '?=' . PHP_EOL;
to

Code: Select all

$header .= 'Subject: ' . $this->mailb64_if_required($this->subject) . PHP_EOL;

Code: Select all

$header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
to

Code: Select all

$header .= 'From: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->from . '>' . PHP_EOL;

Code: Select all

$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
to

Code: Select all

$header .= 'Reply-To: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->from . '>' . PHP_EOL;

Code: Select all

$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->reply_to . '>' . PHP_EOL;
to

Code: Select all

$header .= 'Reply-To: ' . $this->mailb64_if_required($this->sender) . ' <' . $this->reply_to . '>' . PHP_EOL;

So you do not have to constantly do:

Code: Select all

if (mb_check_encoding($this->xxxxxx, 'ASCII')) {
} else {
}
keeps it clean.

Hi i dont have this code "$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->reply_to . '>' . PHP_EOL;"

i have this code "$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->reply_to) . '?= <' . $this->reply_to . '>' . PHP_EOL;"

Im Running opencart 3.0.3.8