I am attempting to hookup SendGrid for automated account confirmation and password recovery. I am using ASP.net webform application and c#. I have installed the NuGet SendGrid package. I am attempting to amend the IdentityConfig.cs file.
The package builds ok. When I register a new user I get the following error: Could not load file or assembly 'SendGrid, Version=9.10.0.0, Culture=neutral, PublicKeyToken=4f047e93159395ca' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
However, the user does get added to the ASPNetUsers database table.
As always, I am very grateful for any help. My code is:
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using SendGrid.Models;
using SendGrid.Helpers.Mail;
using System.Collections.Generic;
namespace SendGrid
{
public class EmailService : IIdentityMessageService
{
public async Task SendAsync(IdentityMessage message)
{
await configSendGridasync(message);
}
// Use NuGet to install SendGrid (Basic C# client lib)
private async Task configSendGridasync(IdentityMessage message)
{
var apiKey = System.Web.Configuration.WebConfigurationManager.AppSettings["SendGrid_API_Key"];
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage();
msg.SetFrom(new EmailAddress("azure_test@azure.com", "Me"));
msg.AddTo(message.Destination);
msg.SetSubject("Testing the SendGrid C# Library");
msg.AddContent(MimeType.Text, "Hello World plain text!");
msg.AddContent(MimeType.Html, "<p>Hello World!</p>");
var response = await client.SendEmailAsync(msg);
// Create a Web transport for sending email.
//var transportWeb = new Web(credentials);
//// Send the email.
//if (transportWeb != null)
//{
// await transportWeb.DeliverAsync(msg);
//}
//else
//{
// Trace.TraceError("Failed to create Web transport.");
// await Task.FromResult(0);
//}
}
}
User contributions licensed under CC BY-SA 3.0