Sendgrid-csharp: I have issue with _emailSender.SendEmailAsync,

Created on 18 Jul 2016  Â·  11Comments  Â·  Source: sendgrid/sendgrid-csharp

Issue Summary

Issue with executing:
await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
$"Please confirm your account by clicking this link: link");
errors:
An unhandled exception occurred while processing the reques

Steps to Reproduce

Occurred when executing public async Task Register(RegisterViewModel model, string returnUrl = null) in AccountController.cs

help wanted question

All 11 comments

Hi @cathyd0701,

Could you please let us know what version of .NET and SendGrid client you are using?

Thank you so much for response.

.NET 4.5.2, sendgrid v7.0.6

Best regards,
Cathy

2016-07-18 15:49 GMT-04:00 Elmer Thomas [email protected]:

Hi @cathyd0701 https://github.com/cathyd0701,

Could you please let us know what version of .NET and SendGrid client you
are using?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/281#issuecomment-233437984,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMj45QkmgmmDu6wNMOLBWFtlC1opWNQ9ks5qW9jBgaJpZM4JPD_U
.

Thank you, that definitely helps.

Can you please share the relevant code (please remove any sensitive data)? If you are not comfortable with sharing publicly, you can email us at [email protected]. Thanks!

Hi,

I called from here: for email confirmation purpose
public async Task Register(RegisterViewModel model,
string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email,
Email = model.Email };
var result = await _userManager.CreateAsync(user,
model.Password);
if (result.Succeeded)
{
// For more information on how to enable account
confirmation and password reset please visit
http://go.microsoft.com/fwlink/?LinkID=532713
// Send an email with this link
var code = await
_userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action("ConfirmEmail", "Account",
new { userId = user.Id, code = code }, protocol:
HttpContext.Request.Scheme);
await _emailSender.SendEmailAsync(model.Email, "Confirm
your account",
$"Please confirm your account by clicking this
link: link");
//await _signInManager.SignInAsync(user, isPersistent:
false);
_logger.LogInformation(3, "User created a new account
with password.");
return RedirectToLocal(returnUrl);
}
AddErrors(result);
}

        // If we got this far, something failed, redisplay form
        return View(model);
    }

failed at await _emailSender.SendEmailAsync

errors reported as :Errors:
An unhandled exception occurred while processing the request.
InvalidApiRequestException: Bad Request Check Errors for a list of errors
returned by the API.

2016-07-18 15:58 GMT-04:00 Elmer Thomas [email protected]:

Thank you, that definitely helps.

Can you please share the relevant code (please remove any sensitive data)?
If you are not comfortable with sharing publicly, you can email us at
[email protected]. Thanks!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/281#issuecomment-233440355,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMj45b7eQKjFq2X0mPRCwnoldvSuZCrtks5qW9rqgaJpZM4JPD_U
.

continue ...

I have API Key, name is GKey-CJazz, I found it was put in var
credentials = new System.Net.NetworkCredential(
Options.SendGridUser,
Options.SendGridKey);

Options.SendGridUser, and the actually api key was put in
Options.SendGridKey

2016-07-18 16:01 GMT-04:00 cdeng cdeng [email protected]:

Hi,

I called from here: for email confirmation purpose
public async Task Register(RegisterViewModel model,
string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email,
Email = model.Email };
var result = await _userManager.CreateAsync(user,
model.Password);
if (result.Succeeded)
{
// For more information on how to enable account
confirmation and password reset please visit
http://go.microsoft.com/fwlink/?LinkID=532713
// Send an email with this link
var code = await
_userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action("ConfirmEmail",
"Account", new { userId = user.Id, code = code }, protocol:
HttpContext.Request.Scheme);
await _emailSender.SendEmailAsync(model.Email,
"Confirm your account",
$"Please confirm your account by clicking this
link: link");
//await _signInManager.SignInAsync(user, isPersistent:
false);
_logger.LogInformation(3, "User created a new account
with password.");
return RedirectToLocal(returnUrl);
}
AddErrors(result);
}

        // If we got this far, something failed, redisplay form
        return View(model);
    }

failed at await _emailSender.SendEmailAsync

errors reported as :Errors:
An unhandled exception occurred while processing the request.
InvalidApiRequestException: Bad Request Check Errors for a list of
errors returned by the API.

2016-07-18 15:58 GMT-04:00 Elmer Thomas [email protected]:

Thank you, that definitely helps.

Can you please share the relevant code (please remove any sensitive
data)? If you are not comfortable with sharing publicly, you can email us
at [email protected]. Thanks!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/281#issuecomment-233440355,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMj45b7eQKjFq2X0mPRCwnoldvSuZCrtks5qW9rqgaJpZM4JPD_U
.

It looks like you are trying to use the 7.X.X version of the library with the 6.X.X examples. For the current documentation, please head over to the current README: https://github.com/sendgrid/sendgrid-csharp. Version 7.X.X was a breaking changes from version 6.X.X

These code actually created by .NET FRAMEWORK core application template...

2016-07-18 16:06 GMT-04:00 Elmer Thomas [email protected]:

It looks like you are trying to use the 7.X.X version of the library with
the 6.X.X examples. For the current documentation, please head over to the
current README: https://github.com/sendgrid/sendgrid-csharp. Version
7.X.X was a breaking changes from version 6.X.X

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/281#issuecomment-233442348,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMj45fopMYouWe_AJhNh4U-_wyH7pDnOks5qW9yzgaJpZM4JPD_U
.

Thanks . Maybe I should try with new code. I just thought the template
should be right previously.

2016-07-18 16:09 GMT-04:00 cdeng cdeng [email protected]:

These code actually created by .NET FRAMEWORK core application template...

2016-07-18 16:06 GMT-04:00 Elmer Thomas [email protected]:

It looks like you are trying to use the 7.X.X version of the library with
the 6.X.X examples. For the current documentation, please head over to the
current README: https://github.com/sendgrid/sendgrid-csharp. Version
7.X.X was a breaking changes from version 6.X.X

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/281#issuecomment-233442348,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMj45fopMYouWe_AJhNh4U-_wyH7pDnOks5qW9yzgaJpZM4JPD_U
.

@cathyd0701,

In that case, you are not using this library to send your emails. You are using the built in SMTP service. It's possible to use it that way, but I would recommend you try using the examples we have here.

Thank you so much. I will try that. It is so happy I can get helps for
using of SendGrid. I was blocked by the issue for several days.

2016-07-18 16:15 GMT-04:00 Elmer Thomas [email protected]:

@cathyd0701 https://github.com/cathyd0701,

In that case, you are not using this library to send your emails. You are
using the built in SMTP service. It's possible to use it that way, but I
would recommend you try using the examples we have here.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/281#issuecomment-233444708,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMj45aVZ9Cpoye7YiXceoFivLLqhZfRQks5qW97MgaJpZM4JPD_U
.

Solved.

Lot's thanks.

2016-07-18 16:18 GMT-04:00 cdeng cdeng [email protected]:

Thank you so much. I will try that. It is so happy I can get helps for
using of SendGrid. I was blocked by the issue for several days.

2016-07-18 16:15 GMT-04:00 Elmer Thomas [email protected]:

@cathyd0701 https://github.com/cathyd0701,

In that case, you are not using this library to send your emails. You are
using the built in SMTP service. It's possible to use it that way, but I
would recommend you try using the examples we have here.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/281#issuecomment-233444708,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMj45aVZ9Cpoye7YiXceoFivLLqhZfRQks5qW97MgaJpZM4JPD_U
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clairernovotny picture clairernovotny  Â·  4Comments

bogacg picture bogacg  Â·  3Comments

kquinbar picture kquinbar  Â·  4Comments

mawiseman picture mawiseman  Â·  4Comments

ivivanov picture ivivanov  Â·  3Comments