string UserName = SessionManager.Instance.FIRSTNAME.ToString() + " " + SessionManager.Instance.LASTNAME.ToString();
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(SmtpClient);
string palinBody = "Your mail server don't support html content.";
AlternateView plainView = AlternateView.CreateAlternateViewFromString(palinBody, null, "text/plain");
mail.From = new MailAddress(MailFrom);
mail.To.Add(MailTo);
mail.CC.Add(MailCC);
mail.Subject = "Update on Your PI Submission";// mailsubject;
mail.IsBodyHtml = true;
string MailBodies = @"
Dear {UserName},
We would like to inform you that the PI point you raised, [PI Title], has now been closed. Thank you for helping us enhance our processes.
Best regards,
Sanjeet Rawat
Safety Head

Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 13, 2024, 8:03 AM EDT
Hello Sandeep,
Try the below code.
string MailBodies = @" Dear {UserName}, We would like to inform you that the PI point you raised, [PI Title], has now been closed. Thank you for helping us enhance our processes. Best regards, Sanjeet Rawat Safety Head "; MailBodies = MailBodies.Replace("{UserName}", UserName);Thanks
Sandeep KumarRank #1,642 · 937 reputationPosted May 13, 2024, 6:34 AM EDT
not working
Rajeesh MenothRank #118 · 18.4K reputationPosted May 13, 2024, 6:59 AM EDT
Hi,
You can try out my inline email sending article in C# corner.
https://www.c-sharpcorner.com/UploadFile/2a6dc5/send-email-to-multiple-email-addresses-with-inline-image-usi/
Jayraj ChhayaRank #304 · 8.2K reputationPosted May 13, 2024, 6:20 AM EDT
To insert the
UserNamevariable into the email body, you can use string interpolation or concatenation within theMailBodiesstring.string UserName = SessionManager.Instance.FIRSTNAME.ToString() + " " + SessionManager.Instance.LASTNAME.ToString(); string MailBodies = $@" Dear {UserName}, We would like to inform you that the PI point you raised, [PI Title], has now been closed. Thank you for helping us enhance our processes. Best regards, Sanjeet Rawat Safety Head ";By using string interpolation (
$"{UserName}") or concatenation ("Dear " + UserName + ","), you can dynamically insert theUserNamevariable into the email body before sending the email.