简体   繁体   English

使用C#的SendGrid V3 API。 电子邮件未发送

[英]SendGrid V3 api with C#. email not sending

is there something wrong with this code? 这段代码有什么问题吗? I already put my email in my code but I don't get any email. 我已经在代码中放入了电子邮件,但没有收到任何电子邮件。 I have a hint that is it not working because I am using API key ID instead of API key because I can't see my API key because of its only show just once. 我有一个提示,它不起作用,因为我使用的是API密钥ID而不是API密钥,因为我的API密钥仅显示一次,因此看不到我的API密钥。 if is that the reason why is this code not working. 如果是该代码不起作用的原因。 Is there no way to view your API key again? 没有办法再次查看您的API密钥吗?

   public string SendEmailMain()
        {
            SendEmail().Wait();

        }
 static async Task SendEmail()
        {
            common com = new common();
            var apiKey = com.sendGridAPI;
            var client = new SendGridClient(apiKey);
            var from = new EmailAddress("testmail@gmail.com", "test user");
            var subject = "Sending with SendGrid is Fun";
            var to = new EmailAddress("testemai@gmail.com", "teset user");
            var plainTextContent = "and easy to do anywhere, even with C#";
            var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";

            var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
            var response = await client.SendEmailAsync(msg);

        }

the code is working pretty well. 该代码运行良好。 The thing is i'm using the API key ID because instead of the API key that generated by sendgrid. 事情是我正在使用API​​密钥ID,因为不是由sendgrid生成的API密钥。

Please refer to this thread for more info 请参考该主题以获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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