How do I email a FlowDocument and retain its formatting

I have a FlowDocument that I need to email out in WPF. The issue is that formatting is now working correctly. Figured it would simple enough doing it this way;

var fromAddress = new MailAddress("myemail@emailaddress.com", fromID);
var toAddress = new MailAddress(emailAddress, toID);
string boby = new TextRange(doc.ContentStart, doc.ContentEnd).Text;
string subject = "My email";
const string fromPassword = "mypassword"
var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,

    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body,
})
{
    smtp.Send(message);
}

While this works the problem is that it does not preserve the formatting of the FlowDocument doc

edit: Based on the comments I followed the example here;
C# FlowDocument to HTML conversion

The problem being that still doesn't preserve the formatting. It would seem that his FlowDocumentToXhtml does not contain values for text alignment.

Any other ideas?

链接地址: http://www.djcxy.com/p/61134.html

上一篇: 通过COM Interop公开索引器/默认属性

下一篇: 我如何通过电子邮件发送FlowDocument并保留其格式