Emailing Attachments with System.Net.Mail.Mail.MailMessage

Posted by jmgawlik on 19-Feb-2009 10:52

I have been able to successfully send an email message using the System.Net.Mail objects (MailMessage and SmtpClient). My problem is that when I try to add an attachment it doesn't recognize the Add method for the Attachments collection. This is supposed to exist according to the MSDN documentation.

I am try to use the following code:

mailMessage:Attachments:Add(new System.Net.Mail.Attachment("something.pdf")).

but I get:

Could not locate element 'Add' in class

'System.Net.Mail.AttachmentCollection'

Sure enough if I look in the class browser Add isn't in there. I double checked to make sure that I was looking at the right MSDN documentation for the .Net Framework 3.0 and I was, so I'm stuck.

Are there methods that aren't exposed in the ABL? Any ideas would be appreciated.

All Replies

Posted by Peter Judge on 19-Feb-2009 11:28

mailMessage:Attachments:Add(new

System.Net.Mail.Attachment("something.pdf")).

but I get:

Could not locate element 'Add' in class

'System.Net.Mail.AttachmentCollection'

Sure enough if I look in the class browser Add isn't

in there. I double checked to make sure that I was

looking at the right MSDN documentation for the .Net

Framework 3.0 and I was, so I'm stuck.

Are there methods that aren't exposed in the ABL? Any

ideas would be appreciated.

I believe the Add() method takes a generic as an argument - which aren't supported in the ABL. There are a couple of posts in this forum discussing that.

You can see that from the Add method (http://msdn.microsoft.com/en-us/library/ms132404.aspx) to the Collection (http://msdn.microsoft.com/en-us/library/ms132397.aspx).

-- peter

Posted by Simon de Kraa on 19-Feb-2009 11:53

As an alternative maybe you can manipulate the headers and content to send the attachment?

Posted by jmgawlik on 19-Feb-2009 11:59

It's a little annoying that the MailMessage:To collection is accessible and Attachments isn't....of course that's not Progress' fault...but darn it!

Posted by Admin on 19-Feb-2009 12:06

The MailAddressCollection has two versions of Add. One of them expects at String, this one is accessible by Progress. The AttachementCollection just has the Add for the generic type. So nothing accessible from Progress.

collection is accessible and Attachments isn't....of

course that's not Progress' fault...but darn it!

That's a very friendly comment for a missing feature (support for generics) in the ABL Hopefully a future release will include support for generics.

The early beta testers have completely overseen the lack of support for generics...

Posted by jmgawlik on 19-Feb-2009 12:10

Well, I am pretty bummed out about it but I don't want to be rude

Posted by jmgawlik on 19-Feb-2009 12:21

As an alternative maybe you can manipulate the

headers and content to send the attachment?

Sorry, I don't have a lot of experience with manipulating emails. I'm not sure what you mean.

Posted by Simon de Kraa on 19-Feb-2009 15:34

Well, instead of using for example the property "IsBodyHtml" you could theoretically set the internet header.

And maybe the same goes for attachments...

mail = NEW MailMessage().

mail:Headers:Set("Content-Type", 'multipart/mixed').

Or you could switch to something like smtpmail.p...

Posted by jmgawlik on 19-Feb-2009 16:14

So you're thinking that I could put the attachment in the body? I'll definitely play with it before I just go back to using create "outlook.application" ...

Posted by Simon de Kraa on 20-Feb-2009 01:38

Theoretically I think that should be possible, but I don't know how "intelligent" System.Net.Mail behaves (something like "you should use the attachment methods so we strip all header/body information regarding attachments").

Posted by jmgawlik on 24-Feb-2009 10:47

Sorry to leave this thread open for so long everyone. I got distracted away from this project I forgot I left it hanging.

Anyway, for the sake of speed I just ended using the outlook.application objects to get it done. Thanks again everyone.

This thread is closed