Question

I have been ask this question for few days but no answer, i am very new to Umbraco and junior of programming.i am working on trying to get admin user to reset password when they are forget their password and sent them an email to reset their password, after they reset they password they will get a new password to login when they login they we will force them to change password, so for now i am struggle on the HandleForgottenPassword, getting

Object reference not set to an instance of an object. on the yellow line,

enter code here
   [HttpPost]
    [Authorize]
    [ValidateAntiForgeryToken]
    public ActionResult HandleForgottenPassword(ForgottenPasswordViewModel model)
    {
        if (!ModelState.IsValid)
        {
            return PartialView("ForgottenPassword", model);
        }

        //Find the member with the email address
        var name =Member.GetMemberFromLoginName(model.LoginName);
        var findMember = Member.GetMemberFromEmail(model.EmailAddress);

        if (findMember != null)
        {
            //We found the member with that email

            //Set expiry date to 
            DateTime expiryTime = DateTime.Now.AddMinutes(15);

            //Lets update resetGUID property
         //   findMember.getProperty("resetGUID").Value = expiryTime.ToString("ddMMyyyyHHmmssFFFF");

            //Save the member with the up[dated property value
            findMember.Save();

            //Send user an email to reset password with GUID in it
            EmailHelper email = new EmailHelper();
            email.SendResetPasswordEmail(findMember.Email, expiryTime.ToString("ddMMyyyyHHmmssFFFF"));
        }
        else
        {
            ModelState.AddModelError("ForgottenPasswordForm.", "No member found");
            return PartialView("ForgottenPassword", model);
        }

        return PartialView("ForgottenPassword", model);
    }

please help with sending email ( using EmailHelper from the package)

private const string SendGridUsername = "sendGridUsername"; private const string SendGridPassword = "sendGridPassword"; private const string EmailFromAddress = "you@yoursite.com";

public void SendResetPasswordEmail(string memberEmail, string resetGUID) { //Send a reset email to member // Create the email object first, then add the properties. var myMessage = SendGrid.GetInstance();

    // Add the message properties.
    myMessage.From = new MailAddress(EmailFromAddress);

    //Send to the member's email address
    myMessage.AddTo(memberEmail);

    //Subject
    myMessage.Subject = "Umb Jobs - Reset Your Password";

    //Reset link
    string baseURL = HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty);
    var resetURL = baseURL + "/reset-password?resetGUID=" + resetGUID;

    //HTML Message
    myMessage.Html = string.Format(
        "<h3>Reset Your Password</h3>" +
        "<p>You have requested to reset your password<br/>" +
        "If you have not requested to reste your password, simply ignore this email and delete it</p>" +
        "<p><a href='{0}'>Reset your password</a></p>", resetURL);


    //PlainText Message
    myMessage.Text = string.Format(
        "Reset your password" + Environment.NewLine +
        "You have requested to reset your password" + Environment.NewLine +
        "If you have not requested to reste your password, simply ignore this email and delete it" +
        Environment.NewLine + Environment.NewLine +
        "Reset your password: {0}",
        resetURL);

    // Create credentials, specifying your user name and password.
    var credentials = new NetworkCredential(SendGridUsername, SendGridPassword);

    // Create an SMTP transport for sending email.
    var transportSMTP = SMTP.GetInstance(credentials);

    // Send the email.
    transportSMTP.Deliver(myMessage);
} 

when i try to sending the email i got this erro Unable to read data from the transport connection: net_io_connectionclosed.

here is my *web.config *

<system.net>
    <mailSettings>
        <smtp>
            <network host="127.0.0.1" userName="username" password="password" />
        </smtp>
    </mailSettings>
</system.net>

Thank you in advance. MC

Was it helpful?

Solution

If you are on a residential internet connection quite often your ISP will block outgoing email sends by blocking all outbound connections to port 25. This is quite common in the US. Try connecting to a local email server over TCP/IP, or to one on your own internal network.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top