sendgrid / sendgrid-csharp

The Official Twilio SendGrid C#, .NetStandard, .NetCore API Library
https://sendgrid.com
MIT License
1.08k stars 584 forks source link

Emails not delivered status returned http 200 /201 #468

Closed abinashTGG closed 7 years ago

abinashTGG commented 7 years ago

Issue Summary

Hi, I am using the helper class (c#) to send the emails in my Web API which is called with https. What I am observing is the response from the service returns Ok status but the email never get delivered. I had a communication with sendgrid helpdesk and they wanted me to post the query here.

I had the test console app which used the same code but I can send the emails from that. Its only my web apis are not sending the code. I am not sure if I am doing anything wrong.

Helpdesk was asking what smtp details I am using but I am not using any smtp servers as I am using helper class to call sendgrid apis.

Here is a sample code dynamic sg = new SendGrid.SendGridAPIClient(ApiKey); Email fromEmail = new Email(FromEmailAddress); Email toEmail = new Email(to); Content content = new Content("text/html", " ");//Empty Content. For some reason we need this one even though the content is being handled via a template Mail mail = new Mail(fromEmail, subject, toEmail, content); mail.TemplateId = templateId; mail.Personalization[0].Substitutions = dataModel;//Data to replace the placeholders in the template mail.MailSettings = new MailSettings() { SandboxMode = new SandboxMode()}; mail.MailSettings.SandboxMode.Enable = false; //Enabling sandbox wont deliver the actual email. Set to false var response = await sg.client.mail.send.post(requestBody: mail.Get()); EmailResponse emailResponse = new EmailResponse() { StatusCode = response.StatusCode }; emailResponse.MessageSettingJson = Newtonsoft.Json.JsonConvert.SerializeObject(mail); emailResponse.MessageId = ((string[])((((SendGrid.CSharp.HTTP.Client.Response)response).Headers.Where(h => h.Key == "X-Message-Id").FirstOrDefault().Value)))[0]; if (emailResponse.StatusCode == HttpStatusCode.Accepted || emailResponse.StatusCode == HttpStatusCode.OK) { emailResponse.IsSuccess = true; } return emailResponse;

I capture the http code returned from the service and log it in my log file. What I observe is the emails are not getting delivered, where as I get either accepted/OK status.

Here is the log, if you put it in some json viewer you can see the messageid returned.

PS: I have replaced some words with value "TEST" {"Level": "Debug","Logger": "ApiActivityLogging","Message": {"StatusCode":202,"IsSuccess":true,"MessageId":"QCTQR73aRgKcHolJrv-x9g","MessageSettingJson":"{\"from\":{\"name\":null,\"email\":\"noreply-smtp@eTEST.com\"},\"subject\":\"Welcome to TEST Contract Administration\",\"personalizations\":[{\"to\":[{\"name\":null,\"email\":\"abinashpatra@gmail.com\"}],\"cc\":null,\"bcc\":null,\"subject\":null,\"headers\":null,\"substitutions\":{\"Title\":\"Welcome to TEST Contract Administration\",\"Subtitle\":\"\",\"Model.Recipient\":\"abinashpatra@gmail.com\",\"Model.ImagePath\":\"https://TESTdev.eTEST.com/Content/img\",\"TeaserLine\":\"Welcome to TEST Contract Administration\",\"Model.Body\":\"Dear Abinash P, \r\n

Welcome to TEST Contract Administration. You have been set up as a user for TGG TGG. \r\n In order to access this account please log in using your email address and the password:

werfwetert

at https://TESTdev.test.com.\r\n

If you have any trouble accessing your account, please contact Customer Support at 800-448-8182. \r\n

Thank you for being a valued customer.\r\n

Sincerely, \r\n
TEST Customer Support\r\n
P:800-448-8182\r\n
E:TESTSupport@test.com\r\n
W:www.TEST.com\"},\"custom_args\":null,\"send_at\":null}],\"content\":[{\"type\":\"text/html\",\"value\":\" \"}],\"attachments\":null,\"template_id\":\"48a17699-8315-454b-b8f5-9c2f8fc396c8\",\"headers\":null,\"sections\":null,\"categories\":null,\"custom_args\":null,\"send_at\":null,\"asm\":null,\"batch_id\":null,\"ip_pool_name\":null,\"mail_settings\":{\"bcc\":null,\"bypass_list_management\":null,\"footer\":null,\"sandbox_mode\":{\"enable\":false},\"spam_check\":null},\"tracking_settings\":null,\"reply_to\":null}"},"SourceName": "TGG_CIE","EventTimeStamp": "5/23/2017 2:53:28 PM"}

Could you please help?

Steps to Reproduce

  1. This is the first step
  2. This is the second step
  3. Further steps, etc.

Any other information you want to share that is relevant to the issue being reported. Especially, why do you consider this to be a bug? What do you expect to happen instead?

Technical details:

thinkingserious commented 7 years ago

Hello @abinashTGG,

It looks like you are using an old version of this SDK. Could you please update to the latest version (v9.4.1).

You can find usage documentation here in this repo.

Thanks!

With Best Regards,

Elmer

abinashTGG commented 7 years ago

Hi, I am able to resolve this one. I just found that because of some glitch (guess with CI/CD process)the template id was wrong in the config file. I did take a look at the api key but not the templateid earlier.

Surprisingly it does not give any error neither it logs the activity in the activity logger and that took so long for me.

And I didnot implement the latest SDK. Guess the latest SDK requires a few code change, thanks

thinkingserious commented 7 years ago

Thanks for the follow up @abinashTGG!