Howto configure for receiving system mails

I want my debian/proxmox system to be enabled to send mails to my nethserver mailserver. How can this be enabled? For examle I’d like that mdadm of ProxMox Host is able to send a mail if one disk of the mirror is kicked out of the raid. On my gentoo I have configured this successfully in ssmtp package, but this is not possible with debian/proxmox.

I would be glad, if someone could point me to the right direction.

@Elleni

Hi

Normally Proxmox has no problems to send mail.

Proxmox already comes with Postfix preinstalled, however there’s still no WebGui for configuration.

Sender Account (E-Mail)
This needs to be defined under Datacenter -> Options.

See these here:

These ought to help set your setup rolling… :wink:

My 2 cents
Andy

1 Like

Hi Andy,

I thought postfix is a to big beast for just relaying mails to a real mailserver, so I thought it would be easier to use ssmtp, but this package is unmaintained in debian, but ok, so I try to configure postfix as it is installed anyway, so thanks for the links. I tried to configure it analog to the second link. I am not using my nethserver mailserver yet, as I did not open apropriate port yet (587), so I use my personal emailaccount on an external hoster for first test. Apparently I have to change the from origin, as here is what I get:

postfix/smtpBC3E017FAC0: to=elleni@domain.com, relay=smtp.domain.com[ip.ad.re.ss]:587, delay=0.23, delays=0.13/0.01/0.08/0.01, dsn=5.1.0, status=bounced (host smtp.domain.com[ip.ad.re.ss] said: 550 5.1.0 root@proxhostname.domain.com sender rejected, invalid domain (430) (in reply to MAIL FROM command))
Jun 16 23:08:59 proxhostname postfix/cleanup[23757]: E8A6B17FAC2: message-id=20200616210859.E8A6B17FAC2@proxhostname.localdomain
Jun 16 23:09:00 proxhostname postfix/bounce[23760]: BC3E017FAC0: sender non-delivery notification: E8A6B17FAC2
Jun 16 23:09:00 proxhostname postfix/qmgr[22758]: E8A6B17FAC2: from=<>, size=2367, nrcpt=1 (queue active)
Jun 16 23:09:00 proxhostname postfix/qmgr[22758]: BC3E017FAC0: removed
Jun 16 23:09:00 proxhostname postfix/smtp[23759]: E8A6B17FAC2: to=root@proxhostname.domain.com, relay=smtp.domain.com[ip.ad.re.ss]:587, delay=0.31, delays=0.06/0/0.12/0.14, dsn=5.1.1, status=bounced (host smtp.domain.com[ip.ad.re.ss] said: 550 5.1.1 root@proxhostname.domain.com recipient rejected (510) (in reply to RCPT TO command))
Jun 16 23:09:00 proxhostname postfix/qmgr[22758]: E8A6B17FAC2: removed

Hi

The “from” field is very important - since spamming is so common, but you can also change that in the GUI.
If sent by script, you would need to set that in postfix - or your script.

My 2 cents
Andy

well the above happens if I try to send a testmail by just issuing the following in proxmox console:

echo “test message” | mail -s “test subject” elleni@domain.com

So I don’t know how to test the configuration to get a mail sent successfully. Thats why I thought I have to change that somewhere in postfix config, so I am searching for the where and how :slight_smile:

My main.cf looks like that so far:

relayhost = [smtp.domain.com]:587
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sasl_security_options =

And sasl_passwd:
[smtp.domain.com]:587 elleni@domain.com:Mailaccountpassword

The mail command allows you to set the sender…

See part 6 FROM…

Andy

1 Like

Thanks! Understood, so this works if I define the sender the test is successfull and mail delivered. Now the only missing bit remaining is how do I tell postfix, that it shall always use a certain emailadress as from and to for systemmails to root? I understand, that setting the sender in proxmox gui should and probably will work, but what I want to acheive is that for ex. mdam will send mail as soon as the raid gets degraded. Have you done that ? Would you recommend to search for defining sender within mdam or directly in postfix set the mailadress for root somehow so that every service for ex. a cron job automatically sends to this address when sending mail to root? Probably some alias I have to set somewhere… digging the net

I have done this and similiar before, but always from my own scripts, where the sender was a variable set at the top of the script, same as the recipient.

eg

$reciepient = mdadm-users@mydomain.com
$sender = mdadm-SERVERNAME@mydomain.com

These are all legit mail-accounts and domains…

You could also (simpler) create a mail-rule for root, and forward messages using a legit user (not root) to an external mail account. Mailsieve is your friend…

Configure postfix to use your external smarthost…

Andy

I see, I would rather like to have postfix configured that way that mails to root are always sent to a defined emailadress. I thought, I found something and added the follwing in main.cf:

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
virtual_alias_maps = hash:/etc/postfix/virtual

aliases:
postmaster: root
nobody: root
hostmaster: root
webmaster: root
www: root

virtual:
root elleni@domain.com

But it gets ignored. Issuing: echo “test message” | mail -s “test subject” root

Mail from is still: from=root@proxmoxhostname.reavita.work

create a “mailing” user, which uses a legit mail account / mailserver / domain.
Then forward roots mail to this user…

Also a good tip:
Create a DNS entry for that host. No MX, just the host name as A record…

This bit: proxmoxhostname.reavita.work

root itself is not easily modified. Any other user easier!

Well I dont get it. I mean, I am using a legit mailadress, my personal one in fact. I will create a mail, once I got it working. The problem is how do I tell postfix that root’s mails should be sent to this address. Creating a A record I will be able to do once I transfer this solution to nethserver mail, where I am able to modify the dns. But for now, I am trying with an ordinary mailserver. It could be gmail.com mailserver or something, so I cannot create any zone to workaround it. I just need to find out, how I can tell postfix that it shall always use from and to address xy.

you were on the right track, but maybe not the right alias…

Setting the DNS would effectively make root@server-fqdn a legit mail-sender…

I understand, but before trying on my domain where I can modify dns, I’d rather try on the external mailserver to rule out errors on my nethserver mailserver config, for ex. right now, I dont have submission port 587 opened yet.

I tried with following line added in aliases, but no luck.
root: elleni@domain.com

The from= and the to= always stay root@proxmoxhostname.domain.com, damnit, I’d like to know where the f… this is defined :sweat:

Maybe sleep over it and look into it tommorrow again. At least I know, that manually defining the from would work.

1 Like

Some further digging revealed the following. Apparently there are two ways to forward mails. With aliases and also with .forward file in user’s home. There I found the following in /root/.forward:
|/usr/bin/pvemailforward

So I went and created a backup job with email notification. As long as I configured a legit mailadress in datacenter/options/email from address in ProxMox the mail is delivered correctly.

Unfortunately this does not work for mdadm on the same host, as I configured the same legit emailaddress for mailaddr and mailfrom in /etc/mdadm/mdadm.conf. I also get an email, but it looks like this:

The correct mail is attached, with configured mailaddr and mailfrom, but the mail I get says:

This is the mail system at host proxmoxhostname.localdomain. I’m sorry to have to inform you that your message could not be delivered to one or more recipients. It’s attached below. For further assistance, please send mail to postmaster. If you do so, please include this problem report. You can delete your own text from the attached returned message. The mail system elleni@domain.com: host smtp.domain.com[ip.ad.re.ss said: 550 5.1.0 root@proxmoxhostname.localdomain sender rejected, invalid domain (430) (in reply to MAIL FROM command)

Reporting-MTA: dns; proxmoxhostname.localdomain X-Postfix-Queue-ID: 44E9A17FAC2 X-Postfix-Sender: rfc822; root@proxmoxhostname.localdomain Arrival-Date: Wed, 17 Jun 2020 01:30:32 +0200 (CEST) Final-Recipient: rfc822; elleni@domain.com Original-Recipient: rfc822;elleni@domain.com Action: failed Status: 5.1.0 Remote-MTA: dns; smtp.domain.com Diagnostic-Code: smtp; 550 5.1.0 root@proxmoxhostname.localdomain sender rejected, invalid domain (430)

ForwardedMessage.eml

Betreff:

TestMessage event on /dev/md0:proxmoxhostname
Von:

elleni@domain.com
Datum:

17.06.2020, 01:30

An:

elleni@domain.com

This is an automatically generated mail message from mdadm running on hrs A TestMessage event had been detected on md device /dev/md0. Faithfully yours, etc. P.S. The /proc/mdstat file currently contains the following: Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] md0 : active raid1 sda2[0] sdb2[1] 1928159232 blocks super 1.2 [2/2] [UU] bitmap: 8/15 pages [32KB], 65536KB chunk unused devices:

1 Like

Ok, as I have a second proxmox I restarted with a clean postfix configuration, and additionally I found a post, which finaly solved all my problems. The smtp_header_checks file along with installation of postfix-pcre finally made everything work on both of my proxmox nodes, but I only tested the mailnotification for mdadm degraded raid state, and not yet on the non zfs node. General email notification for ex. after a backup works fine on the zfs node too, but I would like to ensure that zfs zed will mail me if one disk goes south.

I tested by setting one disk to faulty on the non zfs proxmox and I immediately got my email notification. One last thing I’d like to know on this topic is is the follwoing. As having had experience with mdadm, I was not afraid to set one disk to faulty. After that I knew removing it from raid and adding it back the sync will start and so it did.

Now I’d like to know, how I could test the same functionality in zfs. Being new to zfs, I thought, better ask then sorry :slight_smile:

1 Like