简体   繁体   English

从文本框中获取电子邮件并使用Gmail发送

[英]Get email from textbox and send using Gmail

Have a look at my email code behind. 看看后面的我的电子邮件代码。

 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;
    }
}

In this code, I have to manually enter the receiver email. 在此代码中,我必须手动输入收件人电子邮件。 My question is how to get email entered onto text box instead of mail.To.Add("color.shadow@yahoo.com"); 我的问题是如何使电子邮件输入文本框而不是mail.To.Add("color.shadow@yahoo.com"); Thanks in advance! 提前致谢!

Change mail.To.Add("color.shadow@yahoo.com"); 更改mail.To.Add("color.shadow@yahoo.com"); to mail.To.Add(textBoxEmail.Text); mail.To.Add(textBoxEmail.Text); if you have created a textbox called textBoxEmail . 如果您创建了一个名为textBoxEmail的文本框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM