Score:0

Sendmail to send system emails

ly flag

Is there a way to send an email to my Gmail account, each time I get a system email from Ubuntu?

I'm using Ubuntu 22.10 and has Sendmail installed and working (sending emails from/to my Gmail account). When I ssh to the machine, I sometimes see a notification about having a new email waiting (from the server). I would like to receive a notification on my Gmail each time I gat such an email.

I was looking at solutions to possibly use a cron job with Sendmail to achieve this, but I don't know how to design and trigger it. I didn't find any tutorials and it seems to be beyond the scopes of my current knowledge.

Any ideas or alternative solutions will be very appreciated!

Thanks

Edit - some more info:

I've been using Linux for years and thought I knew enough about Ubuntu, but this "system-email" thing got me stuck.

So I first encountered it recently with ddclient, where there's an option to get emails on failure:

mail=root
mail-failure=root

I can read them be running mail from the terminal. This example and others like it, are email notifications from parts of the system, and I just think it would be great to have them sent or forwarded directly to my personal Gmail. I got Sendmail connected to my Gmail account, and that's where I'm stuck now.

Example - when I ssh to the server, I get this message (the last line):

Welcome to Ubuntu 22.10 (GNU/Linux 5.19.0-1006-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

2 updates can be applied immediately.
2 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

You have new mail.
David avatar
cn flag
What is in the emails from the server and who are they from?
raj avatar
cn flag
raj
If sending emails from/to your Gmail account works, can't you just forward email from the account in question (that is the recipient of "emails from server") to your Gmail account? If you don't want to receive the entire message on Gmail, you can forward to a script that sends a simple notification to Gmail using sendmail.
Regev avatar
ly flag
That would probably work, but I can't find a way to do it
raj avatar
cn flag
raj
Did you try the standard `.forward` file? You should put this file in the home directory of the user who receives mail (that is probably `root`) and put your Gmail address inside this file.
Score:0
us flag

Classic initial suggestion is to use procmail for processing messages incoming to user's (non root) mailbox. procmail can use vacation to limit notifications rate.

Which program your sendmail uses as its local delivery agent?

grep ^Mlocal /etc/mail/sendmail.cf

sensible-mda as local mailer means procmail if procmail is installed. In such case ~/.procmailrc works without extra tricks.

Regev avatar
ly flag
That's what I get when I run the command: Mlocal, P=/usr/sbin/sensible-mda,
AnFi avatar
us flag
`sensible-mda` means `procmail` **if procmail is installed**. In such case `~/.procmailrc` works without extra tricks.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.