Pravin Ghadge

Pravin Ghadge

  • 563
  • 2.1k
  • 587.4k

Error:Failure sending mail.

Dec 9 2010 7:23 AM

Hi I have used gmail for sending mail localy which worked fine but when i uploaded the same file on server the "Failure sending mail."
My code is:
MailMessage
mm = new MailMessage("[email protected]", "[email protected]");
mm.Subject = txtSubject.Text;
mm.Body =
"Name: " + txtName.Text + "<br /><br />Email: " + txtEmail.Text + "<br />" + txtBody.Text;
if (FileUpload1.HasFile)
{
string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
mm.Attachments.Add(
new Attachment(FileUpload1.PostedFile.InputStream, FileName));
}
mm.IsBodyHtml =
true;
SmtpClient smtp = new SmtpClient();
smtp.Host =
"smtp.gmail.com";
smtp.EnableSsl =
true;
System.Net.
NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName =
"[email protected]";
NetworkCred.Password =
"xxxxx";
smtp.UseDefaultCredentials =
true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
lblMessage.Text =
"Email Sent SucessFully.";

Answers (1)