.net - 未找到命名空间网络

标签 .net c#-4.0 sendgrid

我正在按照 Microsoft 的教程与 SendGrid 集成。他们的代码是here .

现在我使用 .Net Framework 4.5.2,但出现错误:

  // Create a Web transport for sending email.
  var transportWeb = new Web(credentials);

错误显示“无法找到类型或命名空间名称“Web”。” 我在网上搜索过,但找不到太多相关信息。我已经获得了他们在页面中提到的所有 namespace 。

谁能给我一些线索吗?

谢谢。 贝赫达。

最佳答案

对于其他在尝试将其 MVC 5 项目配置为所有发送确认电子邮件时遇到困难的人来说,这里是信息:

  1. 我正在关注 this page
  2. 我面临的问题是我看不到命名空间 Web
  3. 因此,在 Azure 上创建 SendGrid 帐户后,请使用 Sendgrid.com 上的用户名/密码并获取 API key
  4. 然后使用该 API key ,使用以下代码发送您的电子邮件:

    private async Task configSendGridasync(IdentityMessage message)
    {
        var apiKey = ConfigurationManager.AppSettings["NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"];
        var client = new SendGridClient(apiKey);
        var from = new EmailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1a5b4a2a591b4a9b0bca1bdb4ffb2bebc" rel="noreferrer noopener nofollow">[email protected]</a>", "Example User");
        var subject = message.Subject;
        var to = new EmailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f185948285b19489909c819d94df929e9c" rel="noreferrer noopener nofollow">[email protected]</a>", "Example User");
        var plainTextContent = message.Body;
        var htmlContent = message.Body;
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
    
        await client.SendEmailAsync(msg);
    }
    

以上代码复制自here.

关于.net - 未找到命名空间网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50225944/

相关文章:

javascript - 当我在 Heroku 上部署时 sendGrid 不工作

.net - NCrawler 示例/指南

c# - 如何使用 C# 为所有表单创建通用函数?

c# - 如何更改 WSDL 客户端的预期内容类型?

.net - 在.Net中: best way for keeping CurrentCulture on new Thread?

c# - ASP.NET 3.5 中的 SendGrid Web API

c# - 在 Rider 和 Visual Studio 中使用 C# 和 ASP.Net 的 Git 问题

c# - 对于以 0x85 字符结尾的文件路径(Windows 8),.Net 4.6.1 和 4.6.2 之间的奇怪 Path.GetFullPath 行为不同

rest - 从 REST 服务方法返回原始字符串

php - 为什么使用 SendGrid(和其他服务)