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 + "
Email: " + txtEmail.Text + "
" + 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.";
Error:Failure sending mail.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


Suthish NairRank #92 · 22.8K reputationPosted Dec 9, 2010, 9:40 AM EST