我的问题是我无法代替Susan女士连接电子邮件文本。
请帮助我代替苏珊女士(Susan)
void Sendbutton_Clicked(object sender, System.EventArgs e)
{
var nametext = nameentry.Text;
var emailtext = emailentry.Text;
var subjecttext = subjectentry.Text;
var messagetext = messageeditor.Text;
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(emailtext);
mail.To.Add("jatin.kapoor@gmail.com");
mail.Subject = subjecttext;
string htmlString = @"<html>
<body>
<p>Dear Ms. Susan,</p>
<p>Thank you for your letter of yesterday inviting me to come for an interview on Friday afternoon, 5th July, at 2:30.
I shall be happy to be there as requested and will bring my diploma and other papers with me.</p>
<p>Sincerely,<br>-Jack</br></p>
</body>
</html>
";
答案 0 :(得分:2)
您可以这样做:
string nametext = nameentry.Text;
string htmlString = $@"<html>
<body>
<p>Dear {nametext},</p>
<p>Thank you for your letter of yesterday inviting me to come for an interview on Friday afternoon, 5th July, at 2:30.
I shall be happy to be there as requested and will bring my diploma and other papers with me.</p>
<p>Sincerely,<br>-Jack</br></p>
</body>
</html>";
答案 1 :(得分:1)
我不确定您要做什么,但是string interpolation
比concat
更好。
var name = "Susan";
var message = $"Dear Ms.{name}";
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
答案 2 :(得分:0)
这将为您解决问题:
string htmlString = @"<html><body><p> Dear"
+ nametext
+ @",</p><p>"
+ emailtext
+ @"</p><p>Sincerely,<br>-Jack</br></p></body></html>";