+#define APPEND(format, value) \
+ if ((buf_len > 0) && (strlen(value) > 0)) { \
+ status = ssnprintf(buf_ptr, buf_len, format "\r\n", value); \
+ if (status > 0) { \
+ buf_ptr += status; \
+ buf_len -= status; \
+ } \
+ }
+
+ APPEND("Host: %s", n->host);
+ APPEND("Plugin: %s", n->plugin);
+ APPEND("Plugin instance: %s", n->plugin_instance);
+ APPEND("Type: %s", n->type);
+ APPEND("Type instance: %s", n->type_instance);
+ APPEND("\r\nMessage: %s", n->message);
+
+ pthread_mutex_lock(&session_lock);
+
+ if (session == NULL) {
+ /* Initialization failed or we're in the process of shutting down. */
+ pthread_mutex_unlock(&session_lock);
+ return -1;
+ }
+
+ if (!(message = smtp_add_message(session))) {
+ pthread_mutex_unlock(&session_lock);
+ ERROR("notify_email plugin: cannot set SMTP message");
+ return -1;
+ }
+ smtp_set_reverse_path(message, email_from);
+ smtp_set_header(message, "To", NULL, NULL);
+ smtp_set_message_str(message, buf);
+
+ for (int i = 0; i < recipients_len; i++)
+ smtp_add_recipient(message, recipients[i]);