how to send a message to email after user login to account in asp.net mvc ?
please kindly send code if anyone knows
how to send a message to email after user login to account in asp.net mvc ?
please kindly send code if anyone knows
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anoop Kumar SharmaPosted Oct 4, 2022, 6:03 AM
Hi Prakash,
Please refer to the below article:
https://www.aspsnippets.com/Articles/Send-Email-with-example-in-ASPNet-using-C-and-VBNet.aspx
I hope this will help you.
Paul AwomiPosted Oct 4, 2022, 6:17 AM
using System.Net;
using System.Net.Mail;
public async Task SendMail(string recipientEmail, string senderEmail, string senderPassword, string senderName, string subject, string message)
{
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(senderEmail, senderName);
msg.To.Add(recipientEmail);
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.yourdomainname"; // e.g., mail.exampledomain.com
System.Net.NetworkCredential nt = new NetworkCredential();
nt.UserName = senderEmail; //Sender's Email Address
nt.Password = senderPassword; // Sender's Email Password
smtp.UseDefaultCredentials = true;
smtp.Credentials = nt;
smtp.Port = 25;
smtp.EnableSsl = false;
await smtp.SendMailAsync(msg);
}
catch (Exception)
{
}
}
You can call the 'SendMail(...)' function after you login to send the mail.
I hope this is useful.