Engineering and technology notes

How to Setup SpamAssassin With Postfix On Ubuntu 16.04

This is a comprehensive guide that walks you through the process of securing your Ubuntu 16.04 Postfix email server with SpamAssassin.

By Francis Ndungu, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Unsolicited emails are very annoying because they take up your disk space and waste your time every time you try to weed them out from your inbox . Luckily, SpamAssassin is one of the best Open-source tools for filtering and blocking spam.

Designed in Perl, Apache SpamAssassin uses different approaches to identify and block spam. These include: online blacklist database lookup, checksum based filters, Bayesian algorithm and third party programs.

The highly configurable email filter utility is rule-based and to function effectively, it uses regular expressions to determine if an email contains Spam.

If you have already setup an email server with Postfix, SpamAssassin is a good tool for keeping your inbox free from unwanted emails from hackers and telemarketers.

This is a comprehensive guide that walks you through the process of securing your Ubuntu 16.04 Postfix email server with SpamAssassin.

Prerequisites

  1. An Alibaba Cloud account.
  2. An Alibaba Cloud ECS instance running Ubuntu 16.04 Linux distribution.
  3. Postfix Email Server. See our guide for setting up an email server with Postfix, Dovecot and SquirrelMail on Ubuntu 16.04 Alibaba ECS
  4. A non-root user that can perform sudo tasks on your server.

Step 1: Installing and Configuring SpamAssassin

SpamAssassin is available on the Ubuntu software repository. So before we install it, let’s first update the package information index:

$ sudo apt-get update

Then we can install SpamAssassin with the command below:

$ sudo apt-get install spamassassin spamc

Step 2: Creating a User for SpamAssassin

Next, we need to create a dedicated user for SpamAssassin:

$ sudo adduser spamd --disabled-login

Step 3: Configuring SpamAssassin

After installation, we are going to edit the SpamAssassin configuration file. To do this, open the file /etc/default/spamassassin using nano text editor:

$ sudo nano /etc/default/spamassassin 

To enable SpamAssassin on the system, find the parameter ENABLED and change its value from 0 to 1.

ENABLED =1

Next, we are going to create a SAHOME variable and direct it to SpamAssassin home directory:

SAHOME="/var/log/spamassassin/"

Then, locate the below line on the same file:

OPTIONS="--create-prefs --max-children 5 --helper-home-dir"

Change it to:

OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir /home/spamd/ -s /home/spamd/spamd.log"

To pick the latest updates from SpamAssassin, we are going to change the CRON value from 0 to 1:

CRON =1

When you are done editing the file, press CTRL+X, Y and Enter to save the changes.

Step 4: Adding Rules to SpamAssassin

We can now start adding rules to SpamAssassin. Open the file /etc/spamassassin/local.cf

Using nano text editor:

$ sudo nano /etc/spamassassin/local.cf

Make sure the below parameters and values are set on the file:

rewrite_header Subject [***** SPAM _SCORE_ *****]
required_score          5.0
use_bayes               1
bayes_auto_learn        1

The above parameters tell SpamAssassin to rewrite the subject of each email that surpasses the threshold score of 5.0. When set to 1use_bayes instructs SpamAssassin to use the Bayes algorithm to classify emails as either ham or spam using a mathematical formula based on probability.

The parameter bayes_auto_learn is set to 1 to enable the auto-learning mechanism. Save and close the file by pressing CTRL+X, Y and Enter.

Step 5: Configuring Postfix to Use SpamAssassin as an Email Filter

Next, edit the Postfix master configuration file and instruct it to route emails to SpamAssassin for filtering:

$ sudo nano /etc/postfix/master.cf

Find the line:

smtp inet n - - - - smtpd

Then, add the following information below it:

   -o content_filter=spamassassin
spamassassin unix -     n       n       -       -       pipe
    user=spamd argv=/usr/bin/spamc -f -e  
    /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Note: Please put several spaces before "-o content_filter=spamassassin" .

Save and close the file by pressing CTRL+X, Y and Enter. Then, restart both Postfix and SpamAssassin.

$ sudo service postfix restart
$ sudo service spamassassin restart

Step 6: Testing SpamAssassin Email Filter

To check whether SpamAssassin is working, send an email to your server (e.g. info@example.com) and add include the content below on the email body to trigger the spam check:

XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

Open your email client (in this case, we are using SquirrelMail) and check your inbox. Your email should now be marked as spam and the subject should be re-written to indicate the same.

Conclusion

We have gone through the steps of securing your Postfix email server with SpamAssassin on Ubuntu 16.04 server hosted on Alibaba Cloud. We believe you are going to implement the steps in this article to safeguard your email servers from unwanted emails.

Source: How to Setup SpamAssassin With Postfix On Ubuntu 16.04 – Alibaba Cloud Community

email – TLS – Cert Hostname DOES NOT VERIFY – Stack Overflow

After an SSL certificate change on my virtual server running plesk and ubuntu I suddenly run into an email issue.

Cert Hostname DOES NOT VERIFY (mail.koemanmotoren.nl != www.koemanmotoren.nlhttp://www.checktls.com/perl/TestReceiver.pl

mail: e.g. kleding@koemanmotoren.nl

Indeed this site seems to verify that the hostname is mail.koemanmotoren.nl https://www.ssllabs.com/ssltest/analyze.html?d=koemanmotoren.nl

However I have changed every single hostname I could find, while changing it in plesk or via SSH it automatically changes it anyway everywhere, but somewhere must been another hostname noted?

The certificate is purchased and verified for koemanmotoren.nl and www.koemanmotoren.nl

Source: email – TLS – Cert Hostname DOES NOT VERIFY – Stack Overflow

Cert Hostname DOES NOT VERIFY – Plesk Help Center

Symptoms

  • It is not possible to set up mail client to use secure connection because of SSL warning message about bad certificate
  • If check security with online tools like SSL Labs , it shows warnigns as the following one:

    Cert Hostname DOES NOT VERIFY (mail.example.com != *.example.com | DNS:*.*.example.com | DNS:*.example.com)
    So email is encrypted but the host is not verified

Cause

  • The installed SSL certificate is not wildcard.
  • The multidomain certificate is used and mail.example.com is absent.
  • The mail server certificate is checked using a certificate for a domain that is not used to secure the mail server.

Resolution

Install SSL wildcard certificate or request new SSL certificate having required domain in the list.

In case of multidomain certificate X509v3 Subject Alternative Name should be checked for a domain name.

openssl s_client -showcerts -connect mail.example.com:25 -starttls smtp 2>/dev/null | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ | openssl x509 -noout -text | grep DNS

Note: When connecting to the mail server, make sure to use the domain name in the certificate issued during securing Plesk mail server.
Advise your customers to do the same. Otherwise, the mail client software may be unable to verify the mail server identity, which may cause issues when sending or receiving mail, like this one.

Source: Cert Hostname DOES NOT VERIFY – Plesk Help Center

Is GET data also encrypted in HTTPS?

When you GET

https://encrypted.google.com/search?q=%s

The %s query is encrypted? Or just the response? If it is not, why should Google serve it’s public content also with encryption?

The entire request is encrypted, including the URL, and even the command (GET). The only thing an intervening party such as a proxy server can glean is the destination address and port.

Note, however, that the Client Hello packet of a TLS handshake can advertise the fully qualified domain name in plaintext via the SNI extension (thanks @hafichuk), which is used by all modern mainstream browsers, though some only on newer OSes.

EDIT: (Since this just got me a “Good Answer” badge, I guess I should answer the entire question…)

The entire response is also encrypted; proxies cannot intercept any part of it.

Google serves searches and other content over https because not all of it is public, and you might also want to hide some of the public content from a MITM. In any event, it’s best to let Google answer for themselves.

https://stackoverflow.com/questions/4143196/is-get-data-also-encrypted-in-https

(MMV) Ethernet Shield W5100 connection issue

I have also experienced this problem and from the research I have done there are a number of common parameters:

– The W5100 board is a cheap version from china
– The resistor network immediately behind the Rj45 socket has the value 511 on it (its small get a magnifying glass – it is a black rectangle with 8 connections like a mini IC)

Basically it would appear this component is not correct. I should be 510 or close to this value. Because it is 10 times over spec it is much more sensitive to switches which are sensitive to the voltage on the network.

There are 3 possible fixes:

– Change to a switch that is not as sensitive. There is some discussion on the board about this.
– Change the resistor network to something close to the 49.9R that the arduino schematics suggest it should be. I have only seen one post where someone has done this and gotten it to work. This is fiddly due to the components being so small and surface mount … you would have to be keen to do this.
– Buy a more reputable brand wiznet board or switch to the even cheaper ENC28J60 boards which dont seem to have the same problems.

 
————————————————————————-
Ihope, ican help. I have 3 Ethernet Shields W5100 from China bought. 2 of them had the
erroneous placement. A faulty connection occurs in particular at the when used as a Web client.
The incorrect line termination is apparent in reflections that prevent the connection.
I’ve tried everything, 4 different switches, short lines, long lines … the result was not satisfactory.
Short and sweet – my solution was quite simple:
1. Check to see if the SMD resistors are labeled 511 – see above (important)
2. Installation of two additional resistors 120 Ohm on the circuit side (Bottom Layer),
immediately in connection to the Ethernet jack. One between  1-2, and the other between 3-6.
The body of the resistors should point downwards so that no short circuit with the USB socket of the underlying UNO occurs.
The “1” of the socket is the way to the left (shorter distance to the edge) when the Ethernet socket facing upward, of course, on the ladder page (Bottom Layer) seen.The other terminals follow slightly offset.
After installation, I never had problems again …
I hope my Google English was understandable enough

Source: Ethernet Shield W5100 connection issue