0

I'm running a cloud VM (18.04), and I'm trying to get emails from unattended-upgrades. Can someone tell me the easiest way to get these emails forwarded to me? I've tried several guides for postfix and sendmail, and none of them have managed to send a test email. This all seems overly difficult for forwarding simple system notifications.

Does anyone have a simple solution for this?

James Walters
  • 21
  • 1
  • 1
  • 2
  • Does this answer your question? [What simpler mail server can I use instead of postfix?](https://askubuntu.com/questions/1124620/what-simpler-mail-server-can-i-use-instead-of-postfix) – Organic Marble Dec 24 '19 at 21:08
  • There is a guide on setting up a virtual Postfix mailserver that deals with both sending and receiving emails. It might be worth a look: https://blog.terresquall.com/2022/01/setting-up-a-virtual-postfix-mail-server-part-1/ – John Doe Mar 09 '22 at 17:06

1 Answers1

0

Not sure, if that would help you, but i have used a perl script to check if some condition is true and then send out e-mail.

    #!/usr/bin/perl

    $mailfrom = "root\@myomain.com";
    $mailto = "root\@mydomain.com";

    use FileHandle;

    ##### Check some condition
    if (some condition to be true) {
        push @New,$_;
    }

    ##### Send mail if true
    if (@New) {
        my $data = qx("e-mail body here");
        $mail = new FileHandle;
        $mail->open("| /usr/sbin/sendmail -t") || die "Cannot open: $!";
        $mail->print("From: $mailfrom\n");
        $mail->print("To: $mailto\n");
        $mail->print("Subject: some subject\n\n");
        $mail->print(@New, "\n");
        $mail->print($data, "\n");
        $mail->close();
    }
Taavi
  • 658
  • 1
  • 7
  • 11