Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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...
Posted
Updated 16-Jan-12 23:51pm
v2
Comments
Mukund Thakker 17-Jan-12 5:45am    
can you please add code snipet?
testcapgemini 17-Jan-12 6:20am    
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)
{

}

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900