Hi,
i want to send email with attachment. so when i attach a file and sending email the file is received but no content was displaying the file shows 0KB when i download from mail.
here is the code in
aspx page
string frommail =" from@mail.com";
string subject="Demo mail";
string body="check mail have a attachment";
if (FileUpload1.HasFile.Equals(true))
{
byte[] fileSize = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedfile = FileUpload1.PostedFile;
uploadedfile.InputStream.Read(fileSize, 0, (int)FileUpload1.PostedFile.ContentLength);
string str = txtto.Text.Replace(',',';');
emailaddress = str.Split(';');
foreach (string tomail in emailaddress)
{
if (tomail != "")
{
Boolean mail = _objsendmail.Sendmailwithattachment(frommail,tomail,subject,body,uploadedfile,fileSize);
if (mail == true)
{
Label1.Text = "mail sent successfully";
txtto.Text = "";
txtsubject.Text = "";
MailEditor.Value = "";
}
}
}
}
code in
Sendmailwithattachment function
public Boolean Sendmailwithattachment(string from, string to, string subject, string body, HttpPostedFile uploadedfile, byte[] fileSize)
{
MailMessage message = new MailMessage();
message.From = new MailAddress(from);
string str = to.Replace(',', ';');
emailaddress = str.Split(';');
foreach (string toaddress in emailaddress)
{
if (toaddress != "")
{
message.To.Add(toaddress);
message.Subject = subject;
message.Body = body;
message.Attachments.Add(new Attachment(uploadedfile.InputStream,uploadedfile.FileName));
message.IsBodyHtml = true;
SmtpClient emails = new SmtpClient("10.0.0.1");
emails.Send(message);
return true;
}
}
return false;
}
what is wrong with the code how can i pass my attach file in these function.
please help.
thanks,
parithi