How can I use e-mail notification inside my own scripts ?

  • Hi all,


    I know, that OMV can be configured to sent notifications via e-mail.

    I would be interested, how I can use this mechanism inside my scripts.


    I have a backup script, that is executed every night using cron.

    I know, that I can sent the output from cron via mail, but I am only interested to get a notification it the backup has a problem.

    I can handle all this inside my script, but I don't know, how I can "hand over" some information, that get's then sent to me using the built in mechanism of OMV.


    Any help or pointers to some documentation would be highly appreciated.


    Thanks, quack

    TerraMaster T6-423

    Qnap TS-853A

    Qnap TS-451+

    Qnap TS-259 Pro+

    • Official Post

    I know, that I can sent the output from cron via mail, but I am only interested to get a notification it the backup has a problem.

    I can handle all this inside my script, but I don't know, how I can "hand over" some information, that get's then sent to me using the built in mechanism of OMV.

    Use mailx. Very easy to use.


    echo "message" | mailx -s "subject" receipient@domain.com

    omv 7.7.0-2 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.1 | kvm 7.0.17 | compose 7.3.4 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.0.9


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • sounds like this is completely ignoring the OMV mechanism.

    I would like to do it "the most OMV" way.


    If I change the recipient in the Web-UI, I would like that this changed recipient gets used in the mail i send.

    TerraMaster T6-423

    Qnap TS-853A

    Qnap TS-451+

    Qnap TS-259 Pro+

    • Official Post

    sounds like this is completely ignoring the OMV mechanism.

    I would like to do it "the most OMV" way.


    If I change the recipient in the Web-UI, I would like that this changed recipient gets used in the mail i send.

    This is the OMV way.

    If you want to submit a mail to root simply run echo "foo bar" | mail -E -s "Mail from administrator" root

    • Official Post

    sounds like this is completely ignoring the OMV mechanism.

    I would like to do it "the most OMV" way.

    OMV configures and uses postfix. mailx uses postfix. Volker's suggestion make it seem more OMV.

    omv 7.7.0-2 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.1 | kvm 7.0.17 | compose 7.3.4 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.0.9


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • I'm not sure if I understood you correctly

    (or maybe I could not communicate clearly enough, what I am looking for)


    I tried the above method (echo "foo bar" | mail -E -s "Mail from administrator" root), but it didn't do what I expected.


    I try to explain again, what I am looking for:

    In the Web-UI at "System / Notification / Settings" I have configured an e-mail recipient.


    I am looking for a way to send an e-mail to *that* recipient in the Web-UI.

    Using the above method, i did not receive an e-mail at that address.


    I am looking for a command, that is implicitly using that e-mail address at "System / Notification / Settings".

    (and if I happen to change that address, the command should then send to the changed address, without changing the command)


    Am I missing something, or was the above method not suitable for that purpose?

    TerraMaster T6-423

    Qnap TS-853A

    Qnap TS-451+

    Qnap TS-259 Pro+

    • New
    • Official Post

    Am I missing something, or was the above method not suitable for that purpose?

    The above command send the email to the email configured for root which should be the sender email in the Settings tab. Sending to a user set as a recipient would probably require a short wrapper script around mailx to get the user.

    omv 7.7.0-2 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.1 | kvm 7.0.17 | compose 7.3.4 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.0.9


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Sorry, but I'm not sure, if I understand what you are refering to.


    I try to make it the most specific, I can.


    Let's say I have configured as recipient "OMV-Box@yahoo.com"

    Consequently I have Yahoo configured as my mail provider (SMTP Server, incl. Username and Password).


    All I want to do is sending an e-mail to OMV-Box@yahoo.com using the SMTP-Server at Yahoo.

    (which is all configured in the settings tab)


    I had expected, that there either is an existing command, that I can simply use, and that automatically forwards some arbitrary message to OMV-Box@yahoo.com.


    Or that I maybe need to read the e-mails address, the SMTP server (incl. username and password) from some internal database and then using all that information to put together a command for sending that mail.


    Something similar to the command you or votdev were mentioning. But I'm not sure how to provide the SMTP Server (incl. username and password) to such a command, since this is usually covered by some background service.

    That's why I thought, there should already be something in place, that I could use.


    And even if I need to look up (only) the recipient (i.e. OMV-Box@yahoo.com) somewhere, to put together the mailx command, I currently don't know, where that would be stored.

    TerraMaster T6-423

    Qnap TS-853A

    Qnap TS-451+

    Qnap TS-259 Pro+

    • New
    • Official Post

    The mailx command will use the postfix settings which is the smtp server you set in the notifications tab. The "root" in the command is the recipient. The email will be sent using the "Sender email" email address. Is there a reason you can set the "Sender email" to the email you want to receive it at? Otherwise you will just have to change the recipient manually.


    echo "test" | mailx -s "test email" omv-box@yahoo.com

    omv 7.7.0-2 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.1 | kvm 7.0.17 | compose 7.3.4 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.0.9


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • The mailx command will use the postfix settings which is the smtp server you set in the notifications tab.


    ok, that I do understand and it is how I expected it to work.


    The "root" in the command is the recipient.

    That is the part I don't want. I don't want to send to the local root user. I want to send it to omv-box@yahoo.com, but without the need to set it manually in the command.

    Reason behind that is, that I will probably forget that I hard coded an email address in one of the scripts. If I change the recipient in the settings tab in the future (maybe because I change the mail provider), I will no longer get notified if the script fails.


    The email will be sent using the "Sender email" email address.

    This is ok and also expected.


    Quote

    Is there a reason you can set the "Sender email" to the email you want to receive it at?


    I assume you meant "can't set"?

    No, this is exactly what I want to do. I am setting the the recipient in the settings tab.

    This is working for mails sent by OMV itself.


    I simply want to use the same mechanism from within my scripts.


    Quote


    Otherwise you will just have to change the recipient manually.


    And this is what I want to avoid. I don't want to set it manually.

    I will do it, if there is no other way. But I assume there is...

    TerraMaster T6-423

    Qnap TS-853A

    Qnap TS-451+

    Qnap TS-259 Pro+

    • New
    • Official Post

    If you set the "Sender email" in the Notifications Setting tab, then "root" on the OS will use that address.

    Then if you send using mailx to root like mentioned previously, the email will to the Sender email.

    omv 7.7.0-2 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.1 | kvm 7.0.17 | compose 7.3.4 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.0.9


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!