Hi in my Application i have a requierment of sending email with multiple attachment,
I have done that successfully ,but phasing an straging issue if am attaching more than
One file and send email then,
Except 1 file remaing all other files are blank they lost their data,
Before sending this files as attachment am also upload same no of files into server ,
At that place those attached blank files have theri data but in email except first file all other files are blank..i dont get any exception am not doing any thing with their extensions.....Please help me out ...
Here is my Code ...
try
{
string Frommai = Session["Email"].ToString();
string Tomail = ConfigurationManager.AppSettings["MailCc"].ToString();
string ccmail = ConfigurationManager.AppSettings["MailCc"].ToString();
string mMailServer = string.Empty;
mMailServer = ConfigurationManager.AppSettings.Get("SmtpServer");
Attachment attach;
MailMessage msg = new MailMessage();
MailAddress add = new MailAddress(Frommai, Session["user"].ToString());
msg.From = add;
msg.To.Add(ccmail);
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
string[] strFileName;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
int nFileLen = hpf.ContentLength;
if (hpf.ContentLength > 0)
{
hpf.SaveAs(Server.MapPath("~/resources/MyFiles/" + System.IO.Path.GetFileName(hpf.FileName)));
msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, System.IO.Path.GetFileName(hpf.FileName)));
}
}
msg.Subject = txt_name.Text;
msg.Body = txt_comment.Text;
SmtpClient mySmtpClient = new SmtpClient(mMailServer);
mySmtpClient.UseDefaultCredentials = true;
msg.Priority = MailPriority.High;
msg.IsBodyHtml = true;
mySmtpClient.Send(msg);
}
catch (Exception ex)
{
}
Thanks in Advance...