Sending an email
Date: 02/04/08
(Asp Dot Net) Keywords: asp
I need to send an email in asp.net 2.0 and cant seem to get it working.
Whenever I run the code below I get a "Failure sending mail." error from the Catch.
I know the email settings are correct but I just cant send an email through code.
Can anyone see anything wrong with my code ?
try {
string RecipientEmailAddress = Membership.GetUser("nathan").Email;
//create the mail message MailMessage mail = new MailMessage();
//set the addresses mail.From = new MailAddress("test@phalkensystems"); mail.To.Add("nathan.rimmer@gmail.com");
//set the content mail.Subject = "This is an email"; mail.Body = "this is the body content of the email.";
//send the message SmtpClient smtp = new SmtpClient();
smtp.Host = "smtpout.secureserver.net"; smtp.Port = 70;
//to authenticate we set the username and password properites on the SmtpClient smtp.Credentials = new System.Net.NetworkCredential("test@phalkensystems", "xxxxxxx"); smtp.Send(mail);
}
catch (Exception ex) { Label1.Text = ex.Message.ToString(); }
Source: http://aspdotnet.livejournal.com/95284.html
|