SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Nginx + mail server

Tue Aug 27, 2019 12:51 am

I am trying to configure a mail server with nginx and im having a bit of a problem trying to get it to work. you see when i run my test php which is this

Code: Select all

<?php 
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "a@a.com@YOURDOMAIN";
    $to = "myemail@no.biz";
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
    $headers = "From:" . $from;
    mail($to,$subject,$message, $headers);
    echo "Test email sent";
?>
reports no errors but im still getting nothing in my email.

This is my configurations.

nginx.conf

Code: Select all

mail {
    server_name       mail.example.ca;
    auth_http         localhost:9000/cgi-bin/nginxauth.cgi;

    imap_capabilities IMAP4rev1 UIDPLUS IDLE LITERAL+ QUOTA;

    pop3_auth         plain apop cram-md5;
    pop3_capabilities LAST TOP USER PIPELINING UIDL;

    smtp_auth         login plain cram-md5;
    smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
    xclient           off;

    server {
        listen   25;
        protocol smtp;
    }
    server {
        listen   110;
        protocol pop3;
        proxy_pass_error_message on;
    }
    server {
        listen   143;
        protocol imap;
    }
    server {
        listen   587;
        protocol smtp;
    }
}
I also forwarded the 4 ports above.

Am i missing something?

I followed this guide https://docs.nginx.com/nginx/admin-guid ... ail-proxy/ and punched in

Code: Select all

./configure --with-mail --with-mail_ssl_module --with-openssl=[DIR]/openssl-1.1.1
still no success says not found. to clarify also i need to send and receive.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Wed Aug 28, 2019 11:46 am

*bump

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Fri Aug 30, 2019 6:28 pm

*bump

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Fri Aug 30, 2019 8:41 pm

What's your mail transfer agent?
Does it log errors to /var/log/syslog?

I modified your php program to

Code: Select all

<?php
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "dougie@example.co.uk";
    $to = "example+example@gmail.com";
    $headers = 'From: dougie@example.co.uk' . "\r\n" .
    'Reply-To: dougie@example.co.uk' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
    mail($to,$subject,$message, $headers);
    echo "Test email sent";
?>
I got these headers in the message delivered to GMail

Code: Select all

Return-Path: <dougie@raspberrypi.example.co.uk>
Received: from avasout02.plus.net (avasout02.plus.net. [212.159.14.17])
        by mx.google.com with ESMTPS id v13si5461244wmh.155.2019.08.30.13.34.57
        for <example+example@gmail.com>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 30 Aug 2019 13:34:58 -0700 (PDT)
Received-SPF: neutral (google.com: 212.159.14.17 is neither permitted nor denied by best guess record for domain of dougie@apollo.example.co.uk) client-ip=212.159.14.17;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: 212.159.14.17 is neither permitted nor denied by best guess record for domain of dougie@apollo.example.co.uk) smtp.mailfrom=dougie@apollo.example.co.uk
Received: from apollo.example.co.uk ([xxx.xxx.xxx.xxx]) by smtp with ESMTP id 3nbki8RmRciGj3nbliekln; Fri, 30 Aug 2019 21:34:57 +0100
X-Clacks-Overhead: "GNU Terry Pratchett"
Have you enabled PHP in /etc/nginx/sites-enable/default?

Code: Select all

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sat Aug 31, 2019 3:40 am

server blocks include php

Code: Select all

location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.3-fpm.sock;
	}
mail transfer agent? i think that is the step im missing, im not sure what you mean by that.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sat Aug 31, 2019 7:26 am

SynGreis wrote:
Sat Aug 31, 2019 3:40 am
mail transfer agent? i think that is the step im missing, im not sure what you mean by that.
You need a sendmail equivalent to work (PHP calls sendmail). I got that working by installing postfix and configuring that to use my ISP's mail server on port 25 at 212.159.14.17 (which is obtained from the A record for relay.plus.net).

sudo apt install postfix mailutils

Other MTA are available but I've found that postfix fits my needs and works out of the box on DebIan systems.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
rpdom
Posts: 15194
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Nginx + mail server

Sat Aug 31, 2019 7:31 am

DougieLawson wrote:
Sat Aug 31, 2019 7:26 am
Other MTA are available but I've found that postfix fits my needs and works out of the box on DebIan systems.
Postfix meets my needs too, but I use it as my own mail server instead of using my ISP's one.

I don't have any need for a mail proxy server, so I only use Nginx for webservers.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sat Aug 31, 2019 8:03 am

rpdom wrote:
Sat Aug 31, 2019 7:31 am

Postfix meets my needs too, but I use it as my own mail server instead of using my ISP's one.
You don't have port 25 or 587 open for incoming email, do you?

I'm also using alpine as a text based email reader for stuff sent by cron to my raspberry pi user.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
rpdom
Posts: 15194
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Nginx + mail server

Sat Aug 31, 2019 8:14 am

DougieLawson wrote:
Sat Aug 31, 2019 8:03 am
rpdom wrote:
Sat Aug 31, 2019 7:31 am

Postfix meets my needs too, but I use it as my own mail server instead of using my ISP's one.
You don't have port 25 or 587 open for incoming email, do you?
Yes, I do.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sat Aug 31, 2019 9:26 am

rpdom wrote:
Sat Aug 31, 2019 8:14 am
DougieLawson wrote:
Sat Aug 31, 2019 8:03 am
You don't have port 25 or 587 open for incoming email, do you?
Yes, I do.
So how are you filtering spam? Is Spamassassin any good these days?

And to bring it back on topic that's why PHP's mail() function needs to be avoided if you open your webserver to the public internet with port forwarding. That can turn your webserver into a spam spewing zombie.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
rpdom
Posts: 15194
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Nginx + mail server

Sat Aug 31, 2019 10:58 am

DougieLawson wrote:
Sat Aug 31, 2019 9:26 am
rpdom wrote:
Sat Aug 31, 2019 8:14 am
DougieLawson wrote:
Sat Aug 31, 2019 8:03 am
You don't have port 25 or 587 open for incoming email, do you?
Yes, I do.
So how are you filtering spam? Is Spamassassin any good these days?
What spam? One of the advantages of having a private mailserver on a private domain that isn't advertised anywhere is that I don't get any. If I did I'd consider using ASSP to filter it.

Also, I use dynamic email addressing when signing up for anything. I can say my email address is myemailsomerandomstuffhere at mydomain and it will get through to my main email address unless I tell the server to block it. I don't need to set anything up to use a new email address. That way I can use a new email for anything I sign up for and if I start getting spam to that address I know where it was leaked from. I deliberately didn't use the usual myname+something at whatever format because that is a well known one.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sat Aug 31, 2019 12:39 pm

DougieLawson wrote:
Sat Aug 31, 2019 7:26 am
SynGreis wrote:
Sat Aug 31, 2019 3:40 am
mail transfer agent? i think that is the step im missing, im not sure what you mean by that.
You need a sendmail equivalent to work (PHP calls sendmail). I got that working by installing postfix and configuring that to use my ISP's mail server on port 25 at 212.159.14.17 (which is obtained from the A record for relay.plus.net).

sudo apt install postfix mailutils

Other MTA are available but I've found that postfix fits my needs and works out of the box on DebIan systems.
i selected the internet configuration and its done installing what would be the next step?

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sat Aug 31, 2019 2:06 pm

Try your PHP program by running it in a command line. You may need to use sudo apt install php7.0-cli to get that.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sat Aug 31, 2019 2:38 pm

i run 7.3 and still no go

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sat Aug 31, 2019 3:45 pm

Have you tried your script in a command line/LXterminal?

Assuming the script is called mailer.php and lives in /var/www/html

cd /var/www/html
php mailer.php


Then you can move on to trying to run it from a web browser pointed at NGINX

lynx http://127.0.0.1/mailer.php

Then from a windows machine http://192.168.3.14/mailer.php
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sat Aug 31, 2019 4:25 pm

i ran apt install php7.3-cli

then tried running the script in putty

$ php test.php
postdrop: warning: unable to look up public/pickup: No such file or directory
Test email sent (<-- script echos this)

i already viewed them in my web browser and still nothing.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sat Aug 31, 2019 4:59 pm

sudo mkfifo /var/spool/postfix/public/pickup
sudo systemctl restart postfix
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sat Aug 31, 2019 5:09 pm

ran the commands, it appears still no success.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sat Aug 31, 2019 9:46 pm

Now look in /var/spool/postfix/deferred and /var/spool/postfix/defer and /var/spool/pi to see if there's any rejected email.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sun Sep 01, 2019 12:23 pm

no logs in postfix spool directory and the pi directory in spool doesnt exist.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sun Sep 01, 2019 1:23 pm

How about in /var/spool/mail/* ?

The next move is to run tcpdump to see what's being sent from your RPi to your ISP when your PHP program runs.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sun Sep 01, 2019 2:20 pm

nothing in spool/mail

installed tcpdump but not sure what command you need me to punch in.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sun Sep 01, 2019 5:47 pm

sudo tcpdump -i eth0 -w /var/log/eth0.pcap [assuming it's wired and you've not enabled predictable names].

Then (s)ftp that /var/log/eth0.pcap file to Windows and use Wireshark to read it. You should see everything for port 25 on your ISP's mail server. Wireshark will track a complete TCP/IP stream and decode it.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

SynGreis
Posts: 85
Joined: Tue Nov 07, 2017 6:26 am

Re: Nginx + mail server

Sun Sep 01, 2019 9:40 pm

https://ibb.co/bvrCLSY

this is what i got. i lyped your command waited to listen ran the script and pulled the file and slapped it in wireshark.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Nginx + mail server

Sun Sep 01, 2019 10:44 pm

Which interface is connected to the public internet?
Do you have a firewall blocking port 25?

This is a Wireshark trace from my system, which successfully sent an email to my GMail address.

Image
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Beginners”