I have this code that I am using in my application:
private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress(
"[email protected]", "AB Registration");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
var credentials = new NetworkCredential(
ConfigurationManager.AppSettings["mailAccount"],
ConfigurationManager.AppSettings["mailPassword"]
);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
Trace.TraceError("Failed to create Web transport.");
await Task.FromResult(0);
}
}
It's called here:
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{
var user = new ApplicationUser()
{
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName,
RoleId = (int)ERole.Student,
UserName = model.UserName
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = model.Server +
"/index.html" +
"?load=confirmEmail" +
"&userId=" + user.Id +
"&code=" + HttpUtility.UrlEncode(code);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
}
if (!result.Succeeded)
{
return GetErrorResult(result);
}
return Ok();
}
Is there any way I can get confirmation from sendgrid that the message has been sent or any other information?