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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Anoop Kumar SharmaRank #127 · 17.4K reputationPosted Oct 4, 2022, 2:03 AM EDT
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 Awomi25 reputationPosted Oct 4, 2022, 2:17 AM EDT
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.