Sending Emails like Signup email and forgot password email

Last post 03-03-2009 7:09 PM by dukon360. 2 replies.

Sort Posts:

  • Sending Emails like Signup email and forgot password email

    03-03-2009, 10:02 AM
    • Member
      7 point Member
    • dukon360
    • Member since 03-01-2009, 8:16 AM
    • Posts 19

    I have a txt file named signup.txt and i want it to be sent when a user signs up like when when you sign up for a website you get a signup welcome

    i have the following code to do the job

    this code signs up the user

    public ActionResult Signup(string username, string password, string email)

    {

    //using (new CodeBenchmark())

    {

    JsonResult result = new JsonResult();if (Globals.DisableSignup)

    {

    result.errorMessage =
    "User signup is currently disabled. Try back later";

    }

    else if (string.IsNullOrEmpty(username))

    {

    result.errorMessage =
    "User name cannot be blank.";

    }

    else if (string.IsNullOrEmpty(password))

    {

    result.errorMessage =
    "Password cannot be blank.";

    }

    else if (password.Length < UserManager.MinRequiredPasswordLength)

    {

    result.errorMessage =
    string.Format("Password must be {0} character long.",

    UserManager.MinRequiredPasswordLength);

    }

    else if (string.IsNullOrEmpty(email))

    {

    result.errorMessage =
    "Email cannot be blank.";

    }

    else if (!Globals.IsValidEmail(email))

    {

    result.errorMessage =
    "Invalid email address.";

    }

    else if (!Globals.IsValidUsername(HttpContext, username))

    {

    result.errorMessage =
    "Invalid User name.";

    }

    else

    {

    try

    {

    MembershipCreateStatus status;

    MembershipUser user = UserManager.CreateUser(username, password, email, null, null, true, null,

    out status);if (user == null)

    {

    throw new MembershipCreateUserException(status);

    }

    //The following check is required for TDD

    if (HttpContext != null)

    {

    FormsAuthentication.SetAuthCookie(username, false);

    try

    {

    //Only send mail when we are not running the unit test.

    SendSignupMail(username, password, email);

    result.isSuccessful =
    true;

    }

    catch (Exception e)

    {

    result.errorMessage = e.Message;

    }

    }

    else

    {

    result.isSuccessful =
    true;

    }

    }

    catch (MembershipCreateUserException e)

    {

    result.errorMessage = e.Message;

    }

    }

    return View("Json", result);

    }

    }

    and this one send the email

    private void SendSignupMail(string userName, string password, string email)

    {

    const string CacheKey = "signupMailTemplate";

    var body = HttpContext.Cache[CacheKey] as string;

    if (body == null)

    {

    var file = System.Web.HttpContext.Current.Server.MapPath("~/MailTemplates/Signup.txt");

    body = File.ReadAllText(file);

    HttpContext.Cache[CacheKey] = body;

    }

    body = body.Replace(
    "<%UserName%>", userName);

    body = body.Replace("<%Password%>", password);

    SendMail(email, "Kigg.com: Signup", body);

    }

    but there is an error with

    body = File.ReadAllText(file);

    it says that

    System.Mvc.Web.Controler.File(string, string, string)'is a' Method,' which is not valid in the given context

    does anybody know how to fix this please help

  • Re: Sending Emails like Signup email and forgot password email

    03-03-2009, 1:02 PM
    Answer
    • Member
      68 point Member
    • RobSil
    • Member since 07-03-2008, 4:20 PM
    • Posts 136

     Explicitly define the namespace for File with System.IO.File.ReadAllText(...) and see if that fixes it.  Sounds like it's thinking File is a local method in your controller (or base Controller).

     HTH,

    Rob

  • Re: Sending Emails like Signup email and forgot password email

    03-03-2009, 7:09 PM
    • Member
      7 point Member
    • dukon360
    • Member since 03-01-2009, 8:16 AM
    • Posts 19

    thank you thank really helped if i need anything i'll let you know

Page 1 of 1 (3 items)