--- src/transports/smtp.c.orig 2018-02-08 08:22:40.000000000 -0500 +++ src/transports/smtp.c 2020-05-27 16:12:39.693759381 -0400 @@ -673,12 +673,13 @@ Arguments: addr the address item containing error information host the current host + evstr the event Returns: nothing */ static void -deferred_event_raise(address_item *addr, host_item *host) +deferred_event_raise(address_item * addr, host_item * host, uschar * evstr) { uschar * action = addr->transport->event_action; const uschar * save_domain; @@ -700,7 +701,7 @@ deliver_domain = addr->domain; deliver_localpart = addr->local_part; -(void) event_raise(action, US"msg:host:defer", +(void) event_raise(action, evstr, addr->message ? addr->basic_errno > 0 ? string_sprintf("%s: %s", addr->message, strerror(addr->basic_errno)) @@ -4338,7 +4339,7 @@ #ifndef DISABLE_EVENT if (rc == DEFER) - deferred_event_raise(first_addr, host); + deferred_event_raise(first_addr, host, US"msg:host:defer"); #endif /* If STARTTLS was accepted, but there was a failure in setting up the @@ -4367,10 +4368,22 @@ write_logs(host, first_addr->message, first_addr->basic_errno); # ifndef DISABLE_EVENT if (rc == DEFER) - deferred_event_raise(first_addr, host); + deferred_event_raise(first_addr, host, US"msg:host:defer"); # endif } #endif /*SUPPORT_TLS*/ + +#ifndef DISABLE_EVENT + /* If the last host gave a defer raise a per-message event */ + + if ( !( nexthost + && unexpired_hosts_tried < ob->hosts_max_try + && total_hosts_tried < ob->hosts_max_try_hardlimit + ) + && (message_defer || rc == DEFER) + ) + deferred_event_raise(first_addr, host, US"msg:defer"); +#endif } /* Delivery attempt finished */