I have a script that sends a simple email at the end. When running it while my laptop is inside my university'e network, everything works just fine.
However, when I send an email from home using a command like this
mailx -s "test" [email protected] < mail-test
I can an error message as a return email saying
This is the mail system at host GZsMacbook2019.fritz.box.
I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below. .... : host mx3.mail.icloud.com[184.108.40.206] said: 550 5.7.1 Mail from IP 220.127.116.11 was rejected due to listing in Spamhaus PBL. For details please see http://www.spamhaus.org/query/bl?ip=18.104.22.168 (in reply to RCPT TO command)
It looks like my IP is being blocked because it is listed in Spamhaus's data base. Spamhaus says this about the matter:
Deutsche Telekom advises against accepting e-mail from dialup IPs. We provide these IP addresses dynamically to our customers for internet access. Proper e-mail delivery should use dedicated servers, which is why attempts of e-mail delivery from dialup-ranges generally can be traced to compromised computers or other misuse.
(And, yes, my internet provider is Deutsche Telekom.)
But I need to send the email from a bash script that is executed hourly from cron. The email goes only to myself.
There is also a bit of explanations in Spamhaus' FAQ: https://www.spamhaus.org/faq/section/Legal%20Questions but that does not help.
I think, my home router (FritzBox) does actually run an MTA. And after trying out many of the solutions like the ones suggested at https://tecadmin.net/ways-to-send-email-from-linux-command-line/ or https://stackoverflow.com/questions/2282506/how-can-i-send-an-email-through-the-unix-mailx-command , e.g., Ssmtp or sendmail, I really think the problem is that my IP address (which is assigned to me dynamically by my ISP) is being blocked.
I might be able to use the smarthost of my ISP, but then my script might not work anymore when my laptop is inside my university's network.
Is there any easy way I can send email from a shell script, no matter which network my laptop is in?
Thanks a lot in advance.