المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Sending email in asp.net (using C# & VS 2005)



C# Programming
08-24-2009, 11:19 PM
I am trying to make a program send the email message in a given textbox (here, messageTextBox) when you click on a "Send" button. I cannot seem to get this to work. I am just wondering if someone maybe had some input that would be useful. I am doing this for a website project & have been using my personal emails to test & so far, no luck. Thanks for any & all input!!

protected void sendButton_Click(object sender, EventArgs e)
{
//create mail message
MailMessage mail = new MailMessage();
//set the address
mail.From = new MailAddress("****@yahoo.com");
mail.To.Add("*****@hotmail.com");
//set the content
mail.Subject = "Project email";
mail.Body = messageTextBox.ToString();

//send the message
SmtpClient smtp = new SmtpClient("localhost");
smtp.Credentials = new System.Net.NetworkCredential("****@yahoo.com", "myPassword");
smtp.Host = "mail.yahoo.com";
smtp.Port = 25;

smtp.Send(mail);

}