Removing 'on behalf of' when sending mail using MailGun
Asked Answered
N

5

30

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):

[email protected] on behalf of John Smith <[email protected]>

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

John Smith <[email protected]>

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?

Nephogram answered 9/2, 2015 at 1:50 Comment(1)
Please try to send email to gmail and post the header of received email in above questionShakedown
U
28

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

[email protected] on behalf of [email protected]

When I looked into the full email message header I saw that the sender: in the header was [email protected] and the from: was [email protected]

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 [email protected];
       spf=pass (google.com.....
Sender: [email protected]
From: Persons Name <[email protected]>

make Sender equal to Sender: Persons Name <[email protected]>

Unessential answered 8/4, 2016 at 12:50 Comment(1)
Thanks. This fixed my issue with Mailgun.Holbrooke
C
26

To add to Dhodgin's answer:

The on behalf of message comes up if you're using a subdomain in MailGun such as mail.bar.com and the from email address is using a different domain such as [email protected]
To fix this issue add a custom MIME header "sender" and set it to be the same as the from email address.

To add a custom header using the MailGun api make sure to add a h: prefix such as:

request.AddParameter("h:sender", "John Smith <[email protected]> ");
Chrystalchryste answered 1/8, 2017 at 18:15 Comment(5)
This works, but note the header should be "sender" and not "h:sender". When using the MailGun library, AddParameter adds the h: for you.Nephogram
This save my life! thanks!! btw I had to include the h:, i tried without it but nothing change until i used the h: to indicate the use of a header valuePekan
I had the same experience as @Ray.Ranger
If any Pythonistas are using the requests library, you can add the "h:sender" like this: response = requests.post(url, auth, data={"h:sender": "Name <[email protected]>", ...})Scorch
I use the API and HAD to add h: (only with sender, it don't work)Alexei
W
18

Have you added an mg sub domain?

If you have added a sub-domain such as @mg.domain.com then make sure you send your emails from [email protected]

I had the same problem, as I didn't realize that I wanted to have the sender address [email protected] but I had added - as recommended - a subdomain to mailgun: mg.domain.com.

So when I tried to send an email from [email protected] I got "on behalf of" / "sent by" but as soon as I've used the subdomain [email protected] - the "on behalf" message is gone... stupid me...

Wernher answered 19/8, 2016 at 21:19 Comment(2)
Hmm, in Mailgun's setup they say "We recommend using a subdomain with Mailgun, like “mg.mydomain.com”. Using a subdomain you will still be able to send emails from your root domain e.g. “[email protected]”". If that's true, I wonder what the process would be?Neurotic
Yeah. Mailgun should not say Using a subdomain you will still be able to send emails from your root domain and/or should mention the issues with that setup, which they describe on their own documentation: help.mailgun.com/hc/en-us/articles/…Fluxion
T
3

Are you trying to send from a different domain than the one you setup SPF/DKIM on?

You can only send white-labelled emails from the domain you're authorized with Mailgun.

Transistorize answered 9/2, 2015 at 17:0 Comment(2)
No, I'm sending from the domain that I authorized. In other words the mail.bar.com from above is the one that I've specified in Mailgun.Nephogram
I think that's the problem! You need to have setup foo.com in mailgun since you are sending "from" [email protected] (and not mail.bar.com).Andreeandrei
G
0

For those using SMTP in mailgun subdomain. Set the "From" and "Sender" parameter. eg

message["From"] = 'John Smith <[email protected]>'
message["Sender"] = '[email protected]'
Gymnasium answered 21/7, 2022 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.