查看我背后的电子邮件代码。
protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
mail.To.Add("color.shadow@yahoo.com");
mail.From = new MailAddress("abc@gmail.com");
mail.Subject = "Reservation Status";
string Body = "Greeting from us." +
" You may view your booking details at your profile now." +
" Have a nice day." +
"Thank you.";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("localhost", 25);
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential
(abc@gmail.com", "abcdef");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Send(mail);
Label1.Text = "Mail Send...";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
在此代码中,我必须手动输入接收方电子邮件。我的问题是如何将电子邮件输入到文本框而不是mail.To.Add("color.shadow@yahoo.com");
提前谢谢!
答案 0 :(得分:1)
如果您创建了名为mail.To.Add("color.shadow@yahoo.com");
的文本框,请将mail.To.Add(textBoxEmail.Text);
更改为textBoxEmail
。