To send emails using the Mailgun Golang API without the 'on behalf of' label, you need to ensure that your email configuration is set up correctly. The goal is to have the sender's address appear as follows:

John Smith <john@foo.com>

Currently, your emails may be displaying like this:

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

Steps to Achieve Desired Email Format

  1. Verify SPF and DKIM Settings: Ensure that you have correctly configured SPF and DKIM records for your domain as per Mailgun's guidelines. This is crucial for email authentication and helps prevent spoofing.

  2. Use the Correct From Address: When sending emails, make sure to specify the From address correctly in your API call. It should be formatted as follows:

    mailgun.NewMessage(
        "John Smith <john@foo.com>",
        "Subject Here",
        "Email Body Here",
        "recipient@example.com",
    )
  3. Enable DKIM Signing: When sending the email, ensure that DKIM signing is enabled. This can be done by calling SetDKIM(true) in your code. This step is essential for ensuring that your emails are authenticated properly.

  4. Check for Additional Settings: If you are still encountering issues, review your Mailgun account settings for any additional configurations that may be affecting the email headers.

By following these steps, you should be able to send emails that display the sender's name without the 'on behalf of' notation, ensuring a more professional appearance for your communications.