i got the error like this while attach the file to send a mail but without attachment the message has been send (if i hide attach comment)
the error like this:
-----------------------
System.IO.FileNotFoundException: Could not find file
-------------------------------------
and i use this code :
protected void SendEmailWithAttachment(object sender, EventArgs e)
{
SendEmail(txtTo.Text.Trim(), "", "", txtSubject.Text.Trim(), txtBody.Text.Trim(),System.Net.Mail.MailPriority.High, false);
}
private void SendEmail(string toAddress, string ccAddress, string bccAddress, string subject, string body, System.Net.Mail.MailPriority priority, bool isHtml)
{
body = txtBody.Text.ToString();
subject = txtSubject.Text.ToString();
toAddress = txtTo.Text.ToString();
try
{
SmtpClient smtpClient = new SmtpClient();
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
MailAddress fromAddress = new MailAddress("ramji.kid@gmail.com", "ramji.kid, gmail.Com");
smtpClient.Host = "smtp.gmail.com";
smtpClient.EnableSsl = true;
smtpClient.Port = 25;
NetworkCredential info = new NetworkCredential("ramji.kid@gmail.com", "hi");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = info;
message.From = fromAddress;
message.Priority = priority;
message.To.Add(toAddress);
message.Subject = subject;
if (ccAddress.Length > 0)
{
message.CC.Add(ccAddress);
}
if (bccAddress.Length > 0)
{
message.Bcc.Add(bccAddress);
}
message.IsBodyHtml = isHtml;
message.Body = body;
if (FileUpload1.PostedFile.ContentLength > 0)
{
Attachment attachment = new Attachment(Path.GetFullPath(FileUpload1.PostedFile.FileName));
message.Attachments.Add(attachment);
}
smtpClient.Send(message);
lblMessage.Text = "Email sent to " + toAddress + " successfully !";
}
catch (Exception ee)
{
lblMessage.Text = ee.ToString();
}
}