0

看看我背后的电子邮件代码。

 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"); 提前谢谢!

4

1 回答 1

1

如果您创建mail.To.Add("color.shadow@yahoo.com");mail.To.Add(textBoxEmail.Text);一个名为textBoxEmail.

于 2012-09-16T06:55:52.283 回答