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

مشاهدة النسخة كاملة : Try to get System.Net.Mail to work



C# Programming
06-06-2009, 08:51 PM
I cannot get the System.Net.Mail to send out an email message from my Windows application. The Try Catch reports an the error message 'Failure sending message'. What is causing the error? Below is the code I'm using.

MailAddress objFromMailAddress = new MailAddress("myfromemail@mydomain.com, "");

MailAddress objToMailAddress = new MailAddress("mytoemail@mydomain.com");

MailMessage objMailMessage = new MailMessage(objFromMailAddress, objToMailAddress);

SmtpClient objSmtpClient = new SmtpClient();

objMailMessage.Subject = "Subject line";
objMailMessage.IsBodyHtml = false;
objMailMessage.Body = "Body message";

objSmtpClient.Host = "1and1.com;
objSmtpClient.Port = 587;

try
{
objSmtpClient.Send(objMailMessage);
}
catch (Exception pError)
{
}