adferrand / docker-backuppc

Docker container with BackupPC version 4.x/3.x based on Alpine distribution.
MIT License
72 stars 48 forks source link

$Conf{EMailFromUserName} is overridden by "auto_from on" in /etc/msmtprc #27

Open toggoboge opened 4 years ago

toggoboge commented 4 years ago

I am running the BackupPC v4.3.1 version of the container.

BTW, below I have obscured my domain as 'mydomain.com'.

$Conf{EMailFromUserName} is overridden by "auto_from on" in /etc/msmtprc, meaning the configured from-address is not used in outgoing emails.

Using SMTP_HOST & SMTP_MAIL_DOMAIN environment variables, I have configured the backuppc container to send emails via a local SMTP relay container (docker pull namshi/smtp).

I've created a Gmail account, mailrelay@mydomain.com, for use by the SMTP relay container. The Gmail account has also been setup with an alias, backuppc-server@mydomain.com, and emails sent by a small python script from this address via my local SMTP relay are successfully received as coming from backuppc-server@mydomain.com.

In the backuppc container, I have set $Conf{EMailFromUserName} to backuppc-server@mydomain.com.

When I try to send a test email to backuppc@mydomain.com from inside the container, I see the following:

bash-5.0$ /usr/local/BackupPC/bin/BackupPC_sendEmail -u backuppc@mydomain.com
Sending test email using /usr/sbin/sendmail -t -f backuppc-server@mydomain.com

This successfully sends emails via my local SMTP relay. However, the mails are always received as coming from mailrelay@mydomain.com.

In spite of backuppc-server@mydomain.com being used on the sendmail command-line, I see the following in the headers:

From: mailrelay@mydomain.com X-Google-Original-From: backuppc@mydomain.com

Gmail is not honouring the from-address because mailrelay@mydomain.com has permission to send emails from backuppc-server@mydomain.com, but not from backuppc@mydomain.com.

I think this is happening because the "auto_from on" setting in /etc/msmtprc is causing msmtp to generate the from-address from the Linux username, 'backuppc' in this case. This causes the configured $Conf{EMailFromUserName} to be overridden, and backuppc@mydomain.com is used as the from-address instead of backuppc-server@mydomain.com.

Manually changing "auto_from on" to "auto_from off" in /etc/msmtprc has fixed this for me (at least for test emails - I haven't yet checked other emails auto-sent by BackupPC), and the test email sent by the BackupPC_sendEmail command above, is now received by backuppc@mydomain.com with the from-address is correctly set to backuppc-server@mydomain.com.

toggoboge commented 4 years ago

Oh, if you do decide to update entrypoint.sh to address this, it'd be nice to have an environment variable that allows users to enable msmtp logging, perhaps defaulting the logfile to /home/backuppc/msmtp.log if no path is provided. As I was changing it by hand anyhow, I've also modified /etc/msmtprc to include this line:

logfile /home/backuppc/msmtp.log

adferrand commented 4 years ago

Hello @toggoboge! Just to let you know that I saw your issue and did not forgot it. I will handle it as soon as I have some time.

toggoboge commented 4 years ago

Thanks. Maybe /var/log is a better location for a logfile.

adferrand commented 4 years ago

Hello @toggoboge, I finally got the time to handle this issue.

So, I improved the logic to fit the usecase you described here. Basically:

toggoboge commented 4 years ago

Thanks Adrien. Cheer, Brian

On Sun, Mar 1, 2020 at 4:56 PM Adrien Ferrand notifications@github.com wrote:

Hello @toggoboge https://github.com/toggoboge, I finally got the time to handle this issue.

So, I improved the logic to fit the usecase you described here. Basically:

  • all logs from msmtp are now stored in /var/log/msmtp.log, and also in supervisord stdout. I hope this will help a lot to debug mail issues
  • also, when SMTP_MAIL_DOMAIN is empty (the default), msmtp does not try to rewrite the envelope-from in mails generated by backuppc. So $Conf{EMailFromUserName} will be used, not overwritten. If SMTP_MAIL_DOMAIN is set, the envelope-from will be overwritten to USER@SMTP_MAIL_DOMAIN, like before.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/adferrand/docker-backuppc/issues/27?email_source=notifications&email_token=AIWUU7FDPICAKRNMWOINLKDRFKHSDA5CNFSM4ISYE4R2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENNELZQ#issuecomment-593118694, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIWUU7FOM32ZSCYJKKR5BVTRFKHSDANCNFSM4ISYE4RQ .