Hie... here i'm doing sending password to the respective email that user mentioned for "Forgot password" the namespace you must have to add the following :
using System.Net.Mail;
here i'm taking email from form request statement and sending it in my method 'send email' i'm passing the 'email', 'subject line', 'Message'... here in my class my method like as follows:
string email = "Your-Email-@gmail.com";
string password = "*************";
var loginInfo = new NetworkCredential(email, password);
var msg = new MailMessage();
var smtpClient = new SmtpClient("smtp.gmail.com", 587);
msg.From = new MailAddress(email);
msg.To.Add(new MailAddress(address));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = loginInfo;
smtpClient.Send(msg);
}
now i'n calling my method in post action in controller page:
using System.Drawing;
using System.Net; using System.Net.Mail;
here i'm taking email from form request statement and sending it in my method 'send email' i'm passing the 'email', 'subject line', 'Message'... here in my class my method like as follows:
public void SendEmail(string address, string subject, string message)
{string email = "Your-Email-@gmail.com";
string password = "*************";
var loginInfo = new NetworkCredential(email, password);
var msg = new MailMessage();
var smtpClient = new SmtpClient("smtp.gmail.com", 587);
msg.From = new MailAddress(email);
msg.To.Add(new MailAddress(address));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = loginInfo;
smtpClient.Send(msg);
}
now i'n calling my method in post action in controller page:
SendEmail(retrieve.email, "your password", retrieve.password);
And now here i'm adding my credentials in web.config file as after adding this i'm getting mail... from this credetials syntax is as follows:
<system.net>
<mailSettings>
<smtp from="@Your mail gmail.com">
<network host="smtp.gmail.com" password="Your password" port="587"
userName="here your username"/>
</smtp>
</mailSettings>
</system.net>
here the retrieve.email is having my email coming from the form request.
and retrieve.password that is message to be send to that email which i'm retrieving that from my DB... now after doing the above process now you can send email from your MVC application by using that above methon...
No comments:
Post a Comment