In response to my article on Custom Binary Serialization in .NET, a visitor asked me for a specific example of a custom serialization class of .NET’s MailMessage class.
As I mentioned in the article, I struggled with the MailMessage and MailAddress class because they cannot be serialized unless you use custom serialization (which can be a big pain because it takes quite a bit of time to create a custom class). I spent days trying to serialize the MailMessage class using conventional methods, only to find that there is no quick workaround for it other than custom serialization.
Download My Custom SerialMailMessage Class
If you’re interested in using my class, you can download the SerialMailMessage code here.
Within the zipped file, you will find the following classes:
Please keep in mind that my SerialMailMessage code was intended for a web service, so there were certain limitations built into the design of the classes. If you aren’t using these classes with a web service, you’ll have quite a bit more flexibility than I did. I highly encourage you to modify and improve on my code — there is a shameful lack of useful custom serializable classes available online, hence the reason for me having to write my own.
If you have any questions, please post them as comments so that everyone can benefit from a discussion.
April 23rd, 2008 at 9:49 am
Do you have any sample code for the web service you created that is using the serialized mailmessage class?
[Reply]
DotNetYuppie reply on April 23, 2008:
Do you have any specific questions that I could help you with instead?
[Reply]
April 24th, 2008 at 6:31 pm
What did you do ensure security in your web service?
Preventing spam and so on? Using https?
[Reply]
DotNetYuppie reply on April 24, 2008:
A white list is only practical if you only intend to have your own web server send out e-mails. If you want your web service to be accessible to specific users on any computer/IP address, then you’d have to employ some other mechanism of security.
.NET web services allow for active directory user authentication, but you could also do something as simplistic as a username/password over HTTPS or require a client to use an application GUID that must match up with an existing GUID that you have on your side.
[Reply]
April 25th, 2008 at 1:46 pm
I got my web service to work with your Serializable MailMessage Class. Excellent code.
So the only concertn now is the security. I thought of using SSL, but must admit I’m not that experienced in this area. Is there an easy way to use HTTPS? without a certificate?
[Reply]
DotNetYuppie reply on April 26, 2008:
If you’re in a live environment with clients using the web service, you’ll need to get it signed (and unfortunately pay money). To my knowledge, you can’t do SSL unless you have a certificate that is self-signed (and unverified) or signed by a third-party (and costs money).
Hope this helps,
DNY
[Reply]