hiFI
hiFI

Reputation: 1961

Sending Emails via SendGrid C# SMTP Library aren't getting delivered to Certain domains

My issue is quite similar to this although there weren't any conclusive facts to resolve mine.

Unlike the linked Post, I did the following:

  1. I was able to Authenticate using apikey
  2. I am getting a Response.StatusCode as Success after I send the email
  3. I am using a WinForms app by using the SendGrid Library installed via Nuget although I am looking at having it as a WebJob in Azure AppService down the line.
  4. Validated Single Sender verification
  5. I was able to send Emails to Gmail, Outlook, and Yahoo recipients.
  6. HOWEVER, I WAS NOT able to send emails to recipients of a domain (ie. abc.com) where an account of the same domain was used for Registering as my SendGrid account (ie. [email protected]).
  7. I have tried sending emails to mix of recipients ie. Gmail and abc.com but only the Gmail recipient is getting the mail
  8. I am able to check the logs under Activity and it all said delivered; even for recipients of abc.com although none of the recipients of abc.com haven't got it
  9. I also check in the Quarantine Center of 0365 (https://security.microsoft.com/) but didn't see any messages there.

The Code I am using to execute the is at the simplest form:

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            var apiKey = xxxxxxxx";
            var client = new SendGridClient(apiKey);
            

            var from = new EmailAddress("[email protected]");
            var subject = "Sending with Twilio SendGrid to JKSTOCK";
            var to = new EmailAddress("[email protected]");
            var cc = new EmailAddress("[email protected]");
            var bcc = new EmailAddress("[email protected]");
            var plainTextContent = "Test mail sent from SendGrid using C# to ABC.COM";
            var htmlContent = "<strong>and easy to do anywhere, even with C# to ABC.COM</strong>";
            var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
            msg.AddCc(cc);
            msg.AddBcc(bcc);
            var response = await client.SendEmailAsync(msg).ConfigureAwait(false);

            MessageBox.Show($"Status = {response.StatusCode} Success={response.IsSuccessStatusCode} other:{response.Body.ToString()}");

What I am doing wrong here?

Upvotes: 1

Views: 1024

Answers (1)

philnash
philnash

Reputation: 73075

Twilio developer evangelist here.

It seems likely to me that the mailbox provider you are failing to send to is being more picky with incoming emails than Gmail. You said you have used Single Sender Verification, which is good for testing that you can send emails, but for production use it is better to perform Domain Authentication.

Domain Authentication doesn't just verify that you own the domain and can send from email addresses on the domain, it also sets up SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail) which allow for better verification of emails on the part of the mailbox, building more trust and reputation for your sender. Setting up SPF and DKIM also puts you on the path to enable DMARC (Domain-based Message Authentication, Reporting and Conformance) as well, which can further increase your reputation.

I would investigate Domain Authentication in order to improve your emails chances of landing in inboxes.

Upvotes: 2

Related Questions