Pete,
Could you create your own, serializable version of MailMessage, and provide
conversion functions to and from the .net MailMessage?+
Hmm - that's something I could look at...
The main reason for trying to do this in the first place is to (try to)
avoid the "roll-your-own" approach so that I don't have to worry about
things like attachments etc.
Basically, we have a web service which has two WebMethods: SendMail and
SendMailEx. They do essentially the same thing apart from the fact that
SendMailEx supports attachments via the XML DIME extensions. It all works,
and everyone's happy etc. However, my client has asked me to look into the
possibility of an "enclosed" .NET solution whereby remote sites would build
up a MailMessage object and pass only that to a new WebMethod called
SendMailDotNet. I have said that it probably isn't possible natively because
the MailMessage object itself isn't serializeable, but that it *MAY* be
possible by trying to "wrap" it in something which makes it serializeable so
that it can be passed across the Internet to a Web Service. My client said
that if it involved splitting the MailMessage out into its constituent
parts, then not to bother because we may as well just continue with the
SendMailEx WebMethod. I found some code on the web which took a structure
and converted it into a byte array, but this didn't work for the MailMessage
object either.
I'm struggling to work out why this seems to be so difficult...isn't a
MailMessage object just an object in memory? Why does it seem to be so
difficult to get an array of its bytes? This ought to be the easiest thing
in the world, something like (again, apologies for the C#)...
MailMessage objMailMessage = new MailMessage();
MemoryStream objMS = new MemoryStream();
BinaryFormatter objBinaryFormatter = new BinaryFormatter();
objBinaryFormatter.Serialize(objMS, objMailMessage);
byte[] abytMailMessage = objMS.GetBuffer();
Best,
Mark