emailgomailgundkim

Removing 'on behalf of' when sending mail using MailGun


I'm trying to figure out how to send mails using the MailGun Golang API without having it sent 'on behalf of'.

This is how the From address currently looks (where foo.com is the sender's email domain and bar.com is my domain):

john=foo.com@mail.bar.com on behalf of John Smith <john@foo.com>

What do I need to do so that it looks like this instead:

John Smith <john@foo.com>

I've set up SPF and DKIM according to the MailGun instructions and everything passes as being correct. I've also used SetDKIM(true) when I'm sending out the mail. Is there some setting I'm missing or additional validation I need to do?


Solution

  • You need to set the sender property in the email header to the from address as well most likely.

    I had this same problem using NodeMailer for a node.js project. Gmail and Thunderbird would show the from address fine but Outlook would show the from address as

    emailname=example.com@mail.example.com on behalf of emailname@example.com
    

    When I looked into the full email message header I saw that the sender: in the header was emailname=example.com@mail.example.com and the from: was emailname@example.com

    we looked into the spf and dkim records at first thinking it was an issue there but they were fine and in the email header it even said spf and dkim both were passing so then i noticed the sender header was different than the from and Outlook pays attention to that where gmail and thunderbird don't care as much.

    Try setting the sender header to the from value.

    Here is a sample of part of one of the wrong email headers edited to match example above

    Received-SPF: pass (google.com....
    Authentication-Results: mx.google.com;
           dkim=pass header.i=@mail.example.com;
           spf=pass (google.com.....
    Sender: emailname=example.com@mail.example.com
    From: Persons Name <emailname@example.com>
    

    make Sender equal to Sender: Persons Name <emailname@example.com>