Muhammad Nauman
Muhammad Nauman

Reputation: 17

Cannot send email from SendGrid Account api key

i have created secret key from azure and use in code it's working perfectly fine but when i use secret key create from my gmail account i do not receive any email.

I am using the same code for both send grid api keys one from azure sendgrid account another from my direct sendgrid account but from azure sendgrid account emails are delivering without any error and in sendgrid activities tab also there is recent record but form my direct sendgrid account emails are not delivering and there is not recent record in activity tab.

static async Task Execute()
        {
            dynamic client = new SendGridClient("SG.Ge6udT3CQtKCuGIxhGwqkg.***************-B--zeJXJKnlomAzB2XzQ");
            var msg = new SendGridMessage();
            //[email protected]
            msg.SetFrom(new EmailAddress("[email protected]", "Teamx | Services"));

            var recipients = new List<EmailAddress>
                {
                    new EmailAddress("[email protected]")
                };
            msg.AddTos(recipients);

            msg.SetSubject("Test");

            msg.AddContent(MimeType.Text, "test");
            msg.AddContent(MimeType.Html, "test");

            var response = await client.SendEmailAsync(msg);
        }

Upvotes: 0

Views: 898

Answers (1)

SBFrancies
SBFrancies

Reputation: 4240

Your messages won't be delivered because you don't own or control the gmail.com domain. More details can be found here:

https://sendgrid.com/blog/dont-send-email-from-domains-you-dont-control/

but essentially it's a security feature to stop scammers and your message won't be delivered.

Upvotes: 0

Related Questions