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

مشاهدة النسخة كاملة : System.Net.Mail not working



C# Programming
06-17-2009, 05:00 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(fromemailaddress, "Test");
MailAddress objToMailAddress = new MailAddress(toemailaddress);
MailMessage objMailMessage = new MailMessage(objFromMailAddress, objToMailAddress);

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

NetworkCredential objNetworkCredential = new NetworkCredential(outgoingusername, outgoingpassword, "smtp.1and1.com");

SmtpClient objSmtpClient = new SmtpClient();

objSmtpClient.Host = "smtp.1and1.com";
objSmtpClient.Port = 110;
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.Credentials = objNetworkCredential;

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