Shal

Shal

  • 1.5k
  • 245
  • 3.7k

FileUpload control loses the attactment on every mail send postback.

Apr 14 2021 5:56 AM
Hi am sending multiple mails with and without attachments. problem is i have two mail ids coloums 1 is personal mailID 2 is company mailID. if i send mail for both mailIDs 1st one go with attachment but 2nd one go without attachment beause of postback effect so please help me.
 
kindly find the code below
  1. Parallel.ForEach(dtCustomers.AsEnumerable(), row =>  
  2. {  
  3. SendEmail(row["PERSONAL_EMAILID"].ToString(), subject, string.Format(body, row["ENAME"]));  
  4. SendEmail(row["OFFICIAL_EMAILID"].ToString(), subject, string.Format(body, row["ENAME"]));  
  5. });  
  6. private bool SendEmail(string recipient, string subject, string body)  
  7. {  
  8. string from = txtemailfrom.Text;  
  9. using (MailMessage mail = new MailMessage(txtemailfrom.Text, recipient))  
  10. {  
  11. mail.Subject = txtsubject.Text;  
  12. mail.Body = txtbody.Text;  
  13. if (fileUploader.HasFile)  
  14. {  
  15. string fileName = Path.GetFileName(fileUploader.PostedFile.FileName);  
  16. mail.Attachments.Add(new Attachment(fileUploader.PostedFile.InputStream, fileName));  
  17. }  
  18. mail.IsBodyHtml = false;  
  19. SmtpClient smtp = new SmtpClient();  
  20. smtp.Host = "111.111.1.11";  
  21. smtp.EnableSsl = false;  
  22. NetworkCredential networkCredential = new NetworkCredential(from, "[email protected]");  
  23. smtp.UseDefaultCredentials = true;  
  24. smtp.Credentials = networkCredential;  
  25. smtp.Port = 25;  
  26. smtp.Send(mail);  
  27. ScriptManager.RegisterStartupScript(thisthis.GetType(),  
  28. "alert",  
  29. "alert('Message has been sent successfully.');window.location ='SendBulkMail.aspx';"true);  
  30. }  
i tries saving in session and send but problem is when i send mail without attachment the mails captures the cookies in session and send mail with prev attachment.

Answers (1)