我正在按照 Microsoft 的教程与 SendGrid 集成。他们的代码是here .
现在我使用 .Net Framework 4.5.2,但出现错误:
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
错误显示“无法找到类型或命名空间名称“Web”。” 我在网上搜索过,但找不到太多相关信息。我已经获得了他们在页面中提到的所有 namespace 。
谁能给我一些线索吗?
谢谢。 贝赫达。
最佳答案
对于其他在尝试将其 MVC 5 项目配置为所有发送确认电子邮件时遇到困难的人来说,这里是信息:
- 我正在关注 this page
- 我面临的问题是我看不到命名空间 Web
- 因此,在 Azure 上创建 SendGrid 帐户后,请使用 Sendgrid.com 上的用户名/密码并获取 API key
然后使用该 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/