简体   繁体   中英

mailgun to email address replaced by cc email address

I have an issue with mailgun when send an email with cc param. But when I execute the method, I have got wrong header from cc email.

This is my code

var client = new RestClient
{
    BaseUrl = new Uri("https://api.mailgun.net/v3"),
    Authenticator = new HttpBasicAuthenticator("api", "secret-key")
};

var request = new RestRequest();
request.AddParameter("to", "email.to@gmail.com");
request.AddParameter("cc", "email.cc@gmail.com");
client.Execute(request)

So, Can anyone please help me to resolve this?

This is information from email to

在此输入图像描述

This is what I get from cc Email

在此输入图像描述

Hm, I can't reproduce your problem. I'm getting the same mail message in both to and cc mailboxes with correct addresses. Here is a screen from cc mailbox:

在此输入图像描述

To proceed with the problem, could you please do the following:

  1. Update your question with the exact code you use for calling netgun API. Little things matter here and we should understand what makes difference between your and my calls.

  2. Could you also please update your question with raw mail message got to cc mailbox. In gmail you could do it by clicking down arrow near reply button and selecting "Show original":

在此输入图像描述

There will be a bunch of different headers in the message including to and cc:

在此输入图像描述

Please share with us the whole mail packet you get.

  1. If possible, please check the issue with mail address not on gmail. It works ok for me on gmail but may be in your case it's the root cause of message modification.

Please add a request.Method = Method.POST; in your code, because according to official C# mailgun api documentation .

Could you try this code (with the same order) :

    RestClient client = new RestClient ();
    client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
    client.Authenticator =
        new HttpBasicAuthenticator ("api",
                                    "YOUR_API_KEY");
    RestRequest request = new RestRequest ();
    request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
    request.Resource = "{domain}/messages";
    request.AddParameter ("from", "Email From <email.from@gmail.com>");
    request.AddParameter ("to", "email.to@gmail.com");
    request.AddParameter ("cc", "email.cc@gmail.com");
    request.AddParameter ("subject", "Email Subject");
    request.AddParameter ("text", "Testing some Mailgun awesomness!");
    request.AddParameter ("o:tracking", false);
    request.Method = Method.POST;
    return client.Execute (request);

Regards

Hi I cant seem to replicate your problem however, whenever i use mailgun i use the following code and it works fine for me. if you want to give this a try.

public static IRestResponse SendSimpleMessage(string email)
    {
        var order = new CustomerOrder();
        RestClient client = new RestClient();
        client.BaseUrl = new Uri("https://api.mailgun.net/v3");
        client.Authenticator =
                new HttpBasicAuthenticator("api",
                                           "key-MINE");
        RestRequest request = new RestRequest();
        request.AddParameter("domain",
                             "DOMAINHERE.mailgun.org", ParameterType.UrlSegment);
        request.Resource = "{domain}/messages";
        request.AddParameter("from", "Shop Staff <postmaster@EMAILTHING>");
        request.AddParameter("to", email);
    request.AddParameter("cc", "Shop Staff <insert email here>");
        request.AddParameter("subject", "Your Order has been placed");
        request.AddParameter("text", "Thank you for placing an order with our shop, we have just begun processing your order. You will recieve a follow up email when your order is ready for collection");
        request.Method = Method.POST;
        return client.Execute(request);
    }

and then simply call it with

ResponseModel.SendSimpleMessage(email);

EDIT: the only issue i can see in your code is that it is lacking

request.Method = Method.POST;

POST Methods are defined as the following "POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server"

I hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM