Sending mails with attachments curiosity
-
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
-
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
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
-
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
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
-
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
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
-
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
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