0

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

Gab
  • 101
  • 1
    You can't send from this IP. Therefore, you need a relay mail server. – Panki Feb 07 '20 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 07 '20 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" – realpclaudio Feb 07 '20 at 13:00
  • Does your university provides you access to unix/linux account via ssh? – AnFi Feb 09 '20 at 00: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 '20 at 01:17
  • Thanks a lot for your comment. After further investigation, the problem seems to be the IP from which I am sending when at home. In that case, my IP is dynamically assigned by my ISP, and the IP range is marked as "bad" in Spamhaus. So, the problem, I think, is not so much the Unix command, but my ISP, or rather, how can I circumvent the "bad" IP range. I could ssh into my university, and the the email from there, but that would complicate the cron bash script ... maybe, I'll just send the emails only when the script has ascertained that I'm inside the university network. – Gab Feb 17 '20 at 17:22
  • @Isaac: Sorry, but I don't see how I can upvote your comment. – Gab Feb 17 '20 at 17:23

0 Answers0