cancelmsg removes a message from the mail queue. There will be no more attempts to deliver this message, and a standard delivery failure notice is sent to the return address listed on the message. You can only cancel your own messages. The superuser can cancel any message. An attempt to cancel a message will fail if the message has already been sent (of course), or if a delivery attempt is currently in progress. Because a delivery attempt is usually started as soon as an E-mail message is added to the mail queue, a cancellation attempt is only effective if the message cannot be immediately delivered for some reason, or if the system is very busy and is working on a mail backlog. cancelmsg works by marking all pending recipients as undeliverable. A non-delivery report is then generated and sent in the normal fashion.
msgid is the message queue id that can be obtained from the mailq(1), command. A reason is optional. The message does not disappear into a black void. The message will be returned as undeliverable, citing reason. A generic error message will be used if reason is not specified.
A non-delivery report may not be sent immediately, but delayed until the message's turn comes up in the scheduling queue.
There is no immediate indication if the message cancellation worked. A subsequent non-delivery report is the only indication of a successful cancel. If it doesn't come, it means the message wasn't cancelled in time.
A non-delivery report will not be sent for recipients whose delivery status notification does not include the FAIL notice.