c#


MVC ForgotPassword method not sending reset email


I have following GET and POST method in my AccountController:
// GET: /Account/ForgotPassword
[AllowAnonymous]
public ActionResult ForgotPassword()
{
return View();
}
//
// POST: /Account/ForgotPassword
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.Email);
if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
{
// Don't reveal that the user does not exist or is not confirmed
return View("ForgotPasswordConfirmation");
}
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here");
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
// If we got this far, something failed, redisplay form
return View(model);
}
This uses the standard ForgotPassword method defined by Visual studio. I just put an actionlink on my login View like this:
<p>
#Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>
The problem is, I don't get a reset e-mail for a registered user after submitting the email I want to reset in the ForgotPassword view. Is there anything wrong in my code?
I have also configured the mail settings in my Web.config like this, so this shouldn't be the problem:
<mailSettings>
<smtp from="MyEmail">
<network host="smtp.gmail.com" port="587" userName="MyEmail" password="MyEmailPassword" enableSsl="true" />
</smtp>
</mailSettings>
I have tried answers to alike questions on Stackoverflow like changing the line:
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here");
to
UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here");
But that did not work. I also allowed low security apps to send e-mail to my account. I also tried setting deliveryMethod="Network" under my smtp tag but that also did not help.
What could be the problem for not receiving the reset e-mail?
Gmail smtp doesn't send email until you give access to low secure app and enable email forwarding protocol.
After enabling email forwarding (POP) you should get email from google saying someone trying to send email like message and from the mail you can enable low secure app to send email through gmail.

Related Links

Where do i find the ValueType constructor in .net source code?
How to get string value in brackets with regex
Convert multiform cURL request to C# post web request
How to save data grid values to sql database whole values to one primary key i tried but it doesnt work
How to check whether you are getting data from data base?
Click a tab button on website
Enum cannot reference a type through an expression
UnityContainer resolve all types for one interface
.NET DLL Binding Issues
How to read <table> into 'onmouseover' event with C# and HTMLAgilityPack
Content Page does not have content of Master Page
Preload database in xamarin ios
Cannot check or uncheck DataGridViewCheckBoxColumn cells programmatically on UI
From Free/Pro to In-App Purchase
Generic objects managed automatically by a ListBox control? [closed]
NinjectDependencyResolver fails binding ModelValidatorProvider

Categories

HOME
pact
google-cloud-pubsub
redux
marie
cluster-analysis
cxf
casting
azure-database-mysql
jshell
gnuradio
pdf-generation
install
jquery-select2
wavefront
doctrine2
google-my-business-api
dynamics-crm-2011
webseal
openstack-horizon
luis
loss
beacon
scotty
functional-dependencies
launchd
git-submodules
edirectory
undo
language-detection
keil
postgresql-9.6
mootools
incapsula
aweber
azure-storage-files
stencyl
sknode
ape-phylo
directadmin
test-kitchen
qtwebkit
yank
ionic2-select
google-cloud-shell
runtime-permissions
cancan
photoshop-script
jenkins-docker
webmatrix
androiddesignsupport
dynatable
qudpsocket
zsh-completion
mac-app-store
dbi
universe
db2-zos
avi
razorengine
mod
pyshark
ideavim
code-translation
music-player
jsondoc
bluetooth-lowenergy-4.2
google-finance-api
maven-antrun-plugin
tinymce-plugins
strcpy
douglas-peucker
esri-arc-engine
pysvn
unityvs
register-allocation
xmlserializer
parallel-port
rpt
visual-studio-setup-proje
nodeunit
cvi
flask-mongoengine
nvcc
netbeans-plugins
ardor3d
xcode5.1
fade
raddatepicker
caroufredsel
magicsuggest
antixsslibrary
esi
motorola-droid
maven-eclipse-plugin
jqzoom
clgeocoder
pex-and-moles
backlight
hs-err
mass-emails
database-agnostic
qprocess
large-data-volumes
time-management
retrospectiva
asp.net-1.1

Resources

Encrypt Message