phplaravelemailhtml-emailemail-headers

How do I prevent auto-replys (out-of-office/ DNR/etc) to my automated emails? (laravel)


I have a bulk emailer that sends marketing updates to a list of users. We want legitimate responses from our users to come back to our customer service email address, but for reasons irrelevant to the problem, I can't filter them out on the receiving end.

I'm wondering if there's a header, or something I can add that prevents auto-responses from being returned.


Solution

  • After more digging for an answer that seems like a pretty common problem than I was prepared for, I stumbled on this question about how to suppress auto-replys in C# that took me down a Microsoft wormhole into MSDN docs, mentioning the X-Auto-Response-Suppress header - more on this headers options

    It's also mentioned, but not explained in the symphony Docs

    What I found was yes, there is a header that can be attached, and from what I can tell, it has varying levels of success with being honored by different email servers. Microsoft/Exchange seems to have the most documentation around it, so I suspect they support it pretty widely, but I don't have experience with actually using this yet - will update after implementation.

    I'm formatting this for Laravel, but the header should be widely applicable to any language/framework.

    Here's how to add to an email builder in laravel:

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $this->view('emails.orders.shipped');
     
        $this->withSwiftMessage(function ($message) {
            $message->getHeaders()->addTextHeader(
                'X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply'
            );
        });
     
        return $this;
    }
    
    

    Here are the keys and their meaning:

    Key Meaning
    DR Suppress delivery reports from transport.
    NDR Suppress non-delivery reports from transport.
    RN Suppress read notifications from receiving client.
    NRN Suppress non-read notifications from receiving client.
    OOF Suppress Out of Office (OOF) notifications.
    AutoReply Suppress auto-reply messages other than OOF notifications.
    None Don't suppress anything
    All Suppress everything