2

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?

Community
  • 1
  • 1
Xaphann
  • 3,195
  • 10
  • 42
  • 70
  • 3
    I believe you need to convert `FlowDocument` to HTML and send the email using HTML body – Bolu Apr 09 '15 at 15:49
  • 1
    As stated above you'll want to convert the document to HTML (to preserve formatting). One approach to do so is described @ http://stackoverflow.com/questions/6236483/c-sharp-flowdocument-to-html-conversion . Once you've converted it, make sure to send with `IsBodyHtml` set to `true` – kdtong Apr 09 '15 at 15:53

0 Answers0