# Icinga automated Mail

**URL:** <https://community.icinga.com/t/icinga-automated-mail/14799>\
**Category:** Icinga Director\
**Created:** [April 16, 2025, 7:14am UTC](https://community.icinga.com/t/icinga-automated-mail/14799 "2025-04-16T07:14:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julius](https://community.icinga.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@Julius](https://community.icinga.com/u/Julius)\
**Post date:** [April 16, 2025, 7:14am UTC](https://community.icinga.com/t/icinga-automated-mail/14799/1 "2025-04-16T07:14:45Z")

</div>

Hello, i set everything up so that i receive Emails, but only when i trigger them over the IcingaWeb.  
But if I set up a Host, connect it and cut it from the network, Icinga registered it but it doesnt send an email.  
This is the users.conf

```auto
object User "icingaadmin" {
  import "generic-user"

  display_name = "Icinga 2 Admin"
  groups = ["icingaadmins"]

  email = "root@localhost"
}

object User "kaemper" {
  display_name = "Julius Kaemper"
  email = "this is the correct email"
  groups = ["icingaadmins"]
}

object UserGroup "icingaadmins" {
  display_name = "Icinga 2 Admin Group"
}

```

This is notifications.conf

```auto
apply Notification "mail-icingaadmin" to Host {
  import "mail-host-notification"
  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  //interval = 2h

  //vars.notification_logtosyslog = true

  assign where host.vars.notification.mail
}

apply Notification "mail-icingaadmin" to Service {
  import "mail-service-notification"
  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  //interval = 2h

  //vars.notification_logtosyslog = true

  assign where host.vars.notification.mail
}

```

This is commands.conf

```auto
object NotificationCommand "mail-host-notification" {
  command = [ConfigDir + "/scripts/mail-host-notification.sh"]

  arguments += {
    "-4" = "$notification_address$"
    "-6" = "$notification_address6$"
    "-b" = "$notification_author$"
    "-c" = "$notification_comment$"
    "-d" = {
      required = true
      value = "$notification_date$"
    }
    "-f" = {
      value = "$notification_from$"
      description = "Set from address. Requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SU>
    }
    "-i" = "$notification_icingaweb2url$"
    "-l" = {
      required = true
      value = "$notification_hostname$"
    }
    "-n" = {
      required = true
      value = "$notification_hostdisplayname$"
    }
    "-o" = {
      required = true
      value = "$notification_hostoutput$"
    }
    "-r" = {
      required = true
      value = "$notification_useremail$"
    }
    "-s" = {
      required = true
      value = "$notification_hoststate$"
    }
    "-X" = "$notification_hostnotes$"

```

This is templates.conf

```auto
template Host "generic-host" {
  max_check_attempts = 3
  check_interval = 1m
  retry_interval = 30s

  check_command = "hostalive"
}

/**
 * Provides default settings for services. By convention
 * all services should import this template.
*/
template Service "generic-service" {
  max_check_attempts = 5
  check_interval = 1m
  retry_interval = 30s
}

/**
 * Provides default settings for users. By convention
 * all users should inherit from this template.
*/

template User "generic-user" {

}

/**
 * Provides default settings for host notifications.
 * By convention all host notifications should import
 * this template.
*/
template Notification "mail-host-notification" {
  command = "mail-host-notification"

  states = [Up, Down]
  types = [ Problem, Acknowledgement, Recovery, Custom,
            FlappingStart, FlappingEnd,
            DowntimeStart, DowntimeEnd, DowntimeRemoved ]

 vars += {
    // notification_icingaweb2url = "https://www.example.com/icingaweb2"
    // notification_from = "Icinga 2 Host Monitoring <icinga@example.com>"
    notification_logtosyslog = false
  }

  period = "24x7"
}

/*
 * Provides default settings for service notifications.
 * By convention all service notifications should import
 * this template.
*/
template Notification "mail-service-notification" {
  command = "mail-service-notification"

  states = [OK, Warning, Critical, Unknown]
  types = [ Problem, Acknowledgement, Recovery, Custom,
                 FlappingStart, FlappingEnd,
                 DowntimeStart, DowntimeEnd, DowntimeRemoved ]

  vars += {
    // notification_icingaweb2url = "https://www.example.com/icingaweb2"
    // notification_from = "Icinga 2 Service Monitoring <icinga@example.com>"
    notification_logtosyslog = false
  }

  period = "24x7"

}

```

I appreciate some help, if you have any questions let me know!

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [April 16, 2025, 8:31am UTC](https://community.icinga.com/t/icinga-automated-mail/14799/2 "2025-04-16T08:31:04Z")

</div>

did you wait long enough for all the retries so the host is actually in a hard state?

You can see this in the history of the service or hostobject in icingaweb2

---

<div class="post-metadata">

**Author:** ![Julius](https://community.icinga.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@Julius](https://community.icinga.com/u/Julius)\
**Post date:** [April 16, 2025, 8:47am UTC](https://community.icinga.com/t/icinga-automated-mail/14799/3 "2025-04-16T08:47:33Z")

</div>

Hello thank you for your advice!  
Yes i checked again. It is in Hard State rn and i dont get a notification.

---

<div class="post-metadata">

**Author:** ![Julius](https://community.icinga.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@Julius](https://community.icinga.com/u/Julius)\
**Post date:** [April 16, 2025, 12:11pm UTC](https://community.icinga.com/t/icinga-automated-mail/14799/4 "2025-04-16T12:11:57Z")

</div>

I used [How to configure notifications in Icinga2 Director | Andreas ‘ads’ Scherbaum](https://andreas.scherbaum.la/post/2021-11-10_how-to-configure-notifications-in-icinga2-director/)  
this tutorial and it worked!
