Hi burningice, how do we actually use your code?
I cloned your repo and when I tried nothing gets serialized… bear in mind I am using sql server where everything is serialized into json, what I got was only an empty json string ["{}"]
,
Then I realized this is because everything is private
in your SerializeableMailMessage
class, so I change everything into public properties.
For example…
//I changed this...
//private readonly string _body;
//into this...
public string Body { get; set; }
Then it gets serialized into json ‘properly’, however upon deserialization I still get TypeConverter cannot convert from System.String
error…
I finally gave up and wrote a simple code like so… (it is obviously does not support everything MailMessage
has but it is adequate for my needs at the moment).
[Serializable]
public class SimpleMailMessage
{
public string From { get; set; }
public string DisplayName { get; set; }
public string To { get; set; }
public string ReplyTo { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public MailMessage ToMailMessage()
{
return new MailMessage
{
Body = Body,
From = new MailAddress(From, DisplayName),
IsBodyHtml = true,
Subject = Subject,
To = { To },
ReplyToList = { ReplyTo }
};
}
}