I have email sending problem through ASP.Net by the following class. Email goes fine on our own server but it doesn't send email on other servers especially yahoo and hotmail. If anybody helps whats the problem
//////////////email class/////////////////////
private void SendMail(string mailBody)
{
//Create message object and populate w/ data from form
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new System.Net.Mail.MailAddress("webmaster@nust.edu.pk");
message.To.Add(txtemail.Text.Trim());
message.Subject = "UG Admission 2009";
message.Body = mailBody;
message.IsBodyHtml=true;
//Setup SmtpClient to send email. Uses web.config settings.
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
//Error handling for sending message
try
{
smtpClient.Send(message);
//Exception contains information on each failed receipient
}
catch (System.Net.Mail.SmtpFailedRecipientsException recExc)
{
for (int recipient = 0; recipient < recExc.InnerExceptions.Length - 1; recipient++)
{
System.Net.Mail.SmtpStatusCode statusCode;
//Each InnerException is an System.Net.Mail.SmtpFailed RecipientException
statusCode = recExc.InnerExceptions[recipient].StatusCode;
if ((statusCode == System.Net.Mail.SmtpStatusCode.MailboxBusy) || (statusCode == System.Net.Mail.SmtpStatusCode.MailboxUnavailable))
{
//Log this to event log: recExc.InnerExceptions[recipient].FailedRecipient
System.Threading.Thread.Sleep(5000);
smtpClient.Send(message);
}
else
{
//Log error to event log.
Response.Write(recExc.InnerExceptions[recipient].StatusCode);// or use statusCode);
}
}
}
//General SMTP execptions
catch (System.Net.Mail.SmtpException smtpExc)
{
//Log error to event log using StatusCode information in
// smtpExc.StatusCode;
}
catch (Exception ex)
{
//Log error to event log.
}
}
///////////////////end code/////////////////////////////
Thanks for your suggestion
Shakeel ur Rehman