Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. mail attachment repeating

mail attachment repeating

Scheduled Pinned Locked Moved ASP.NET
helpcsharpcom
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kvsreedhar
    wrote on last edited by
    #1

    Please anyone may help! I am trying a program to send a attachment(only one attachment) to 3 mail recepiants . After sending the mail (a success one) I am finding that the attachment sent to each of the recepient is attached thrice(same file is attached to the mail) whereas I am attaching only a single file. And more over I am getting the mail twice as if I clicked on the SEND button twice(infact I clicked only once). Please help me . I give my code as below :rose:thanks in advance :rose: protected void Button1_Click(object sender, EventArgs e) { string[] addresses = {"mailaddress1","mailaddress2","mailaddress3" }; SmtpClient smtpMail = new SmtpClient(); smtpMail.Host = "smtp.abc.com"; smtpMail.EnableSsl = true; MailMessage mail = new MailMessage(); mail.From = new MailAddress("abc@abc.com"); string fileName = Path.GetFullPath(FileUpload1.PostedFile.FileName); for (int i = 0; i < addresses.Length; i++) { if (FileUpload1.PostedFile != "") { try { mail.Attachments.Add(new Attachment(fileName)); } catch (Exception ex) { Response.Write(ex.Message); } } mail.To.Add(addresses[i]); Response.Write(addresses[i] + " "); mail.Subject = "HAI!!!!!!!"; mail.Body = "ATTACH TO ALL"; smtpMail.Credentials = new System.Net.NetworkCredential(username.Text, txtPassword.Text); try { smtpMail.Send(mail); Response.Write(" Mail Sent"); } catch (Exception ex) { Response.Write("Error " + ex.InnerException); Console.WriteLine(ex.InnerException); } } }//end of event click

    Kovuru Sreedhar

    W 1 Reply Last reply
    0
    • K kvsreedhar

      Please anyone may help! I am trying a program to send a attachment(only one attachment) to 3 mail recepiants . After sending the mail (a success one) I am finding that the attachment sent to each of the recepient is attached thrice(same file is attached to the mail) whereas I am attaching only a single file. And more over I am getting the mail twice as if I clicked on the SEND button twice(infact I clicked only once). Please help me . I give my code as below :rose:thanks in advance :rose: protected void Button1_Click(object sender, EventArgs e) { string[] addresses = {"mailaddress1","mailaddress2","mailaddress3" }; SmtpClient smtpMail = new SmtpClient(); smtpMail.Host = "smtp.abc.com"; smtpMail.EnableSsl = true; MailMessage mail = new MailMessage(); mail.From = new MailAddress("abc@abc.com"); string fileName = Path.GetFullPath(FileUpload1.PostedFile.FileName); for (int i = 0; i < addresses.Length; i++) { if (FileUpload1.PostedFile != "") { try { mail.Attachments.Add(new Attachment(fileName)); } catch (Exception ex) { Response.Write(ex.Message); } } mail.To.Add(addresses[i]); Response.Write(addresses[i] + " "); mail.Subject = "HAI!!!!!!!"; mail.Body = "ATTACH TO ALL"; smtpMail.Credentials = new System.Net.NetworkCredential(username.Text, txtPassword.Text); try { smtpMail.Send(mail); Response.Write(" Mail Sent"); } catch (Exception ex) { Response.Write("Error " + ex.InnerException); Console.WriteLine(ex.InnerException); } } }//end of event click

      Kovuru Sreedhar

      W Offline
      W Offline
      whatUrunning com
      wrote on last edited by
      #2

      Hi kvsreedhar The attachment is add 3 time because it is inside the for (int i = 0; i < addresses.Length; i++) block. If you remove the for loop it will be attached once.

      www.whatUrunning.com

      K 1 Reply Last reply
      0
      • W whatUrunning com

        Hi kvsreedhar The attachment is add 3 time because it is inside the for (int i = 0; i < addresses.Length; i++) block. If you remove the for loop it will be attached once.

        www.whatUrunning.com

        K Offline
        K Offline
        kvsreedhar
        wrote on last edited by
        #3

        thanks for your replay but without using the loop how can i send to 3 persons with just one click?

        Kovuru Sreedhar

        W 1 Reply Last reply
        0
        • K kvsreedhar

          thanks for your replay but without using the loop how can i send to 3 persons with just one click?

          Kovuru Sreedhar

          W Offline
          W Offline
          whatUrunning com
          wrote on last edited by
          #4

          You only need to create one MailMessage object, attach the attachment once and send it once. The only part that needs to be in the for loop is mail.To.Add(...` [www.whatUrunning.com](http://www.whatUrunning.com) `

          K 1 Reply Last reply
          0
          • W whatUrunning com

            You only need to create one MailMessage object, attach the attachment once and send it once. The only part that needs to be in the for loop is mail.To.Add(...` [www.whatUrunning.com](http://www.whatUrunning.com) `

            K Offline
            K Offline
            kvsreedhar
            wrote on last edited by
            #5

            :) thanks a lot it's working. :)

            Kovuru Sreedhar

            W 1 Reply Last reply
            0
            • K kvsreedhar

              :) thanks a lot it's working. :)

              Kovuru Sreedhar

              W Offline
              W Offline
              whatUrunning com
              wrote on last edited by
              #6

              You are welcome :)

              www.whatUrunning.com

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups