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. General Programming
  3. .NET (Core and Framework)
  4. Sending mails with attachments curiosity

Sending mails with attachments curiosity

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpcsharpsysadminquestion
5 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.
  • A Offline
    A Offline
    Alsvha
    wrote on last edited by
    #1

    Greetings all. I've made an e-mail module for a client where they can send e-mails with attachments to their clients. To minimize against faulty entered e-mails I've made some functionality which removes e-mail adresses which are rejected by the server (error 550). However, then I found something strange. When ever I try to send an e-mail, the attachments get cleared, meaning that my recovery functionality will remove 550-faulty addresses and resend the e-mail but this time withouth the attachment. I've found that if I send the mail successfully - the attachment is also removed after the send. I'm using a wrapper-class around System.Web.Mail namespace and using smtp.mail.send(mailobject) to send the e-mail. There is not much to this wrapper class except some functionality to check whether recipient(s) and sender have been added. Attachments get added by: "myMailObject.Attachments.Add(New MailAttachment(fileName))" Now - to make the short story longer .... Is this "clearing" of attachments inherit .net behaviour? Or would the problem lay elsewhere? Regards --------------------------- 127.0.0.1 - Sweet 127.0.0.1

    D 1 Reply Last reply
    0
    • A Alsvha

      Greetings all. I've made an e-mail module for a client where they can send e-mails with attachments to their clients. To minimize against faulty entered e-mails I've made some functionality which removes e-mail adresses which are rejected by the server (error 550). However, then I found something strange. When ever I try to send an e-mail, the attachments get cleared, meaning that my recovery functionality will remove 550-faulty addresses and resend the e-mail but this time withouth the attachment. I've found that if I send the mail successfully - the attachment is also removed after the send. I'm using a wrapper-class around System.Web.Mail namespace and using smtp.mail.send(mailobject) to send the e-mail. There is not much to this wrapper class except some functionality to check whether recipient(s) and sender have been added. Attachments get added by: "myMailObject.Attachments.Add(New MailAttachment(fileName))" Now - to make the short story longer .... Is this "clearing" of attachments inherit .net behaviour? Or would the problem lay elsewhere? Regards --------------------------- 127.0.0.1 - Sweet 127.0.0.1

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Never tried it, so I never noticed it. But, a workaround is pretty easy. Keep track of the email attachment filenames yourself and don't rely on the MailMessage object to do it for you. If you need to put the attachments back, you already have your own list to refer to so you can do it again. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Never tried it, so I never noticed it. But, a workaround is pretty easy. Keep track of the email attachment filenames yourself and don't rely on the MailMessage object to do it for you. If you need to put the attachments back, you already have your own list to refer to so you can do it again. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        A Offline
        A Offline
        Alsvha
        wrote on last edited by
        #3

        Yep - it is no problem doing a workaround, I did that myself along the same line you mention because my attachments are already persisted in a database. I was just wondering if it was .net behaviour (or messed up code I'm using) and possible if anybody knew something about why :) Thanks for the reply. --------------------------- 127.0.0.1 - Sweet 127.0.0.1

        D 1 Reply Last reply
        0
        • A Alsvha

          Yep - it is no problem doing a workaround, I did that myself along the same line you mention because my attachments are already persisted in a database. I was just wondering if it was .net behaviour (or messed up code I'm using) and possible if anybody knew something about why :) Thanks for the reply. --------------------------- 127.0.0.1 - Sweet 127.0.0.1

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          No idea. I don't see anything in the System.Web.Mail classes that would clear out the Attachments collection. The code never deletes anything from the collection and the collection is never refreshed from the contents of the underlying COM object either. From the Framework's perspective, if the collection is being cleared out, you're doing it somehow. But I find that hard to believe. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          A 1 Reply Last reply
          0
          • D Dave Kreskowiak

            No idea. I don't see anything in the System.Web.Mail classes that would clear out the Attachments collection. The code never deletes anything from the collection and the collection is never refreshed from the contents of the underlying COM object either. From the Framework's perspective, if the collection is being cleared out, you're doing it somehow. But I find that hard to believe. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            A Offline
            A Offline
            Alsvha
            wrote on last edited by
            #5

            Thanks for the feedback. I didn't read anything about this in the framework description either, but I just couldn't read out of the wrapper code that it would do something like this. I'll try to debug the wrapper intensely and test it, to see if I can find this disparity. --------------------------- 127.0.0.1 - Sweet 127.0.0.1

            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