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
- Parallel.ForEach(dtCustomers.AsEnumerable(), row =>
- {
- SendEmail(row["PERSONAL_EMAILID"].ToString(), subject, string.Format(body, row["ENAME"]));
- SendEmail(row["OFFICIAL_EMAILID"].ToString(), subject, string.Format(body, row["ENAME"]));
- });
- private bool SendEmail(string recipient, string subject, string body)
- {
- string from = txtemailfrom.Text;
- using (MailMessage mail = new MailMessage(txtemailfrom.Text, recipient))
- {
- mail.Subject = txtsubject.Text;
- mail.Body = txtbody.Text;
- if (fileUploader.HasFile)
- {
- string fileName = Path.GetFileName(fileUploader.PostedFile.FileName);
- mail.Attachments.Add(new Attachment(fileUploader.PostedFile.InputStream, fileName));
- }
- mail.IsBodyHtml = false;
- SmtpClient smtp = new SmtpClient();
- smtp.Host = "111.111.1.11";
- smtp.EnableSsl = false;
- NetworkCredential networkCredential = new NetworkCredential(from, "[email protected]");
- smtp.UseDefaultCredentials = true;
- smtp.Credentials = networkCredential;
- smtp.Port = 25;
- smtp.Send(mail);
- ScriptManager.RegisterStartupScript(this, this.GetType(),
- "alert",
- "alert('Message has been sent successfully.');window.location ='SendBulkMail.aspx';", true);
- }
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.