Skip to content

Needed to reboot azure webapp to let SendMail API working #872

@easytruckingET

Description

@easytruckingET

Hi,

we are experiencing a problem related to the sendgrid API that automatically sends e-mail templates from a C#.NET code. As follows you find a functional description of the issue:

  1. When a new user registers to our web platform, the sendgrid API is automatically called by a procedure written in C#

  2. At this point the system should send an e-mail automatically to the user that has registered but nothing happens. In the activity list of the sendgrid dashboard, there is no trace of the mail sent by the system.

  3. We reboot our Azure application and wait some minutes

  4. We manually push a button located in our dashboard that calls the same API of the automatic procedure explained in the point 1. This button attempts again the mail sending to the same e-mail address that has completed the registration to our platform. After some minutes from rebooting and after having pushed the button, the mail is correctly sent to the user and it appears also in the Activity list (well note if we try to push this button before rebooting nothing happens)

As follows you find the text of the C# code that calls the API:

public static async Task<dynamic> SendMail(string apiKey, string templateId, string mailFrom, string mailFromAlias, string mailTo, string mailToAlias, string subject, string body, IEnumerable<KeyValuePair<string, string>> dataToBind, IEnumerable<AttachmentInfo> attachments, bool html)
        {
            dynamic sg = new SendGridAPIClient(apiKey);
            Email from = new Email(mailFrom, mailFromAlias);
            Email to = new Email(mailTo, mailToAlias);
            Content content = new Content(html ? "text/html" : "text/plain", body);
            global::SendGrid.Helpers.Mail.Mail mail = new global::SendGrid.Helpers.Mail.Mail(from, subject, to, content) { TemplateId = templateId };

            foreach (var p in dataToBind)
                mail.Personalization[0].AddSubstitution("-" + p.Key + "-", p.Value);

            if (attachments != null)
                foreach (var attach in attachments)
                    mail.AddAttachment(new Attachment
                    {
                        Filename = attach.FileName,
                        Content = attach.Content,
                        Type = attach.Type
                    });

            dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());

            try
            {
                string resultSendGrid = Newtonsoft.Json.JsonConvert.SerializeObject(response);
                var logPath = ConfigurationManager.AppSettings["LogPath"];
                if (logPath.StartsWith("~"))
                    logPath = System.Web.Hosting.HostingEnvironment.MapPath(logPath);

                System.IO.File.AppendAllText(Path.Combine(logPath,"LogSendgrid.txt"), resultSendGrid);  

            }
            catch (Exception e)
            {
                var errore = e.Message;
            }
            return response;
        }

Is there anybody that has already experienced this issue before that can propose us a possible solution?

We wait your feedbacks, feel free to ask me for any other clarifications

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions