I want to send a message through email in ASP.NET Core 6.0 Web API.
public void SendMail(string password, string to)
{
var host = _config.GetSection("Email:HOST").Value;
var port = _config.GetSection("Email:PORT").Value;
var fromEmail = _config.GetSection("Email:Credentials:Username").Value;
var passwordOfFromEmail = _config.GetSection("Email:Credentials:Password").Value;
var toEmail = to;
using (MailMessage mm = new MailMessage(fromEmail, toEmail))
{
mm.Subject = "Your Secret Password";
// mm.Body = "Your Secret Password is " password;
mm.IsBodyHtml = true;
mm.Body = $"<p>Your Secret Password is " password "</b> To unsubscribe your account, <form method=\"post\" action=\"http://localhost:5000/api/newsletter-subscription/public/unsubscribe\" class=\"inline\"> <input name=\"email\" value="toEmail"> <button type = \"submit\" name = \"submit_param\" value ="toEmail" class=\"link-button\"> Click Here </button> </form>.</p>";
// removed rest
}
}
I got this error:
Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement [Application]
; expected [Application] at
value="toEmail"
CodePudding user response:
you can only use "{toEmail}" to insert email values
mm.Body = $"<p>Your Secret Password is { password }</b> To unsubscribe your account,
<form method=\"post\" action=\"http://localhost:5000/api/newsletter-subscription/public/unsubscribe\" class=\"inline\">
<input name=\"email\" value=\"{toEmail}\"> <button type = \"submit\" name = \"submit_param\"
value = \"{toEmail}\" class=\"link-button\"> Click Here </button> </form>.</p>";