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[] said: 550 5.7.1 Mail from IP was rejected due to listing in Spamhaus PBL. For details please see http://www.spamhaus.org/query/bl?ip= (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.

  • 1
    You can't send from this IP. Therefore, you need a relay mail server.
    – Panki
    Feb 7, 2020 at 12:26
  • mailx is a mail user agent (MUA). By default it tries to send the mail using a local SMTP server (mail transfer agent, MTA). You can either instruct mailx to use your ISP's SMTP server or configure your MTA to do this instead of directly sending to the recipients' SMTP servers. (look for "smarthost") Your MTA could be something like sendmail, exim, postfix or many others.
    – Bodo
    Feb 7, 2020 at 12:35
  • If acceptable you may use a commercial address (i.e. Gmail), and send mail using it. If you use exim, it would be enough to configure it as a "smarthost" and store credentials in "passwd.client" Feb 7, 2020 at 13:00
  • Does your university provides you access to unix/linux account via ssh?
    – AnFi
    Feb 9, 2020 at 0:47
  • Yes, it does. Can you explain to me in more detail how this would help me. Thanks a lot in advance.
    – Gab
    Feb 10, 2020 at 1:17


Browse other questions tagged .