Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7644351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:40:02+00:00 2026-05-31T09:40:02+00:00

How to send a mail through mvc-3 asp.net using c#? I have to send

  • 0

How to send a mail through mvc-3 asp.net using c#?

I have to send a forgot password so how can I do this?
My code is below.

Model code..

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace TelerikLogin.Models.ViewModels
{
    public class ForgotPassword
    {
        public int user_id { get; set; }
        public string user_login_name { get; set; }
        public string user_password { get; set; }

        [Required]
        [Display(Name="Email Address : ")]
        public string user_email_address { get; set; }
    }
}

Controller code..

  public ActionResult ForgotPassword()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ForgotPassword(string user_email_address)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\MVC3\TelerikLogin\TelerikLogin\App_Data\Login.mdf;Integrated Security=True;User Instance=True");

            DataTable dt1 = new DataTable();

            string strQuery = string.Format("SELECT user_password FROM [user_master] WHERE user_email_address='{0}'",user_email_address);
            conn.Open();
            SqlDataAdapter da1 = new SqlDataAdapter(strQuery, conn);
            da1.Fill(dt1);
            conn.Close();

            if (dt1.Rows.Count > 0)
            {

MailMessage msg = new MailMessage();

            msg.From = new MailAddress("abc@gmail.com");
            msg.To.Add(user_email_address);
            msg.Subject = "Password";
            msg.Body = "Test1";
            msg.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient();




            client.Credentials = new NetworkCredential("abc@gmail.com", "dip", "smtp.gmail.com");
            client.Host = "smtp.gmail.com";
            client.Port = 587;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;
            client.UseDefaultCredentials = true;

            client.Send(msg);


               return RedirectToAction("About", "Home");
            }
            return View();
        }

Here I fetched the password of user from database through entered email address..

View code..

<% using (Html.BeginForm("ForgotPassword", "Account", FormMethod.Post))
   { %>

   <%: Html.LabelFor(m => m.user_email_address) %>
   <%: Html.TextBox("user_email_address")%>
      <%: Html.ValidationSummary(true) %>

<input type="submit" value="Submit"/>

   <%} %>

It gives me an error on these line

 client.Send(msg);

Error messege is:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. x1sm1264662igc.16

How to solve it?
thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:40:03+00:00Added an answer on May 31, 2026 at 9:40 am

    Import the System.Net.Mail namespace.

    The code will look similar to this:

    MailMessage mail = new MailMessage();
    
    SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
    smtpServer.Credentials = new System.Net.NetworkCredential("userName", "password");
    smtpServer.Port = 587; // Gmail works on this port
    
    mail.From = new MailAddress("myemail@gmail.com");
    mail.To.Add("recepient@gmail.com");
    mail.Subject = "Password recovery";
    mail.Body = "Recovering the password";
    
    smtpServer.Send(mail);
    

    P.S. You have a SQL injection vulnerability in the sample code. Use a SqlCommand object with parameters instead of String.Format().

    Using SqlDataReader would be a lot more efficient to check for a record instead of populating a DataSet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Send email using System.Net.Mail through gmail. (C#) I am using this code
I'm trying to configure a dedicated server that runs ASP.NET to send mail through
I need to send mail daily using smtp and asp.net.
I am using asp.net 3.5 and C#. I want to send mail from asp.net,
I'm currently looping through a datareader and calling the System.Net.Mail.SmtpClient's Send() method. The problem
I am making use of PHPMailer to send mail through GMail. The code I
How to send mail from any mail id through java? i meant how can
When I send emails through google app engine using the mail's send_mail function, they
I'm using System.Net.Mail.MailMessage to send emails from my C# Windows app. I originally had
I am using the MVC pattern in ASP.NET using service (BLL) and repository layers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.