2012-09-16 2 views
0

내 이메일 코드를 살펴보십시오.텍스트 상자에서 이메일을 보내고 Gmail을 사용하여 보내십시오.

protected void Button1_Click(object sender, EventArgs e) 
{ 

    try 
    { 
     MailMessage mail = new MailMessage(); 
     mail.To.Add("[email protected]"); 

     mail.From = new MailAddress("[email protected]"); 
     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 
      ([email protected]", "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("[email protected]"); 미리 감사드립니다!

답변

1

textBoxEmail이라는 텍스트 상자를 만든 경우 mail.To.Add("[email protected]");에서 mail.To.Add(textBoxEmail.Text);으로 변경하십시오.

관련 문제