找不到命名空间Web

时间:2018-05-08 04:40:58

标签: .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'无法找到。" 我在网上搜索过,但对此并不了解。我已经获得了他们在页面中提到的所有名称空间。

任何人都可以给我一些线索吗?

感谢。 Behdad。

2 个答案:

答案 0 :(得分:0)

检查是否已将SendGrid包添加到项目中。然后,将using SendGrid;添加到您的班级。

如果您已经,可以点击Web并按Alt + Shift + F10查看可用选项。

答案 1 :(得分:0)

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

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

    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("test@example.com", "Example User");
        var subject = message.Subject;
        var to = new EmailAddress("test@example.com", "Example User");
        var plainTextContent = message.Body;
        var htmlContent = message.Body;
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
    
        await client.SendEmailAsync(msg);
    }
    
  5. 以上代码是从here.

    复制的