Emailing a fixed document through Outlook

Posted by MoominTroll on Stack Overflow See other posts from Stack Overflow or by MoominTroll
Published on 2010-03-12T11:10:51Z Indexed on 2010/03/12 11:37 UTC
Read the original article Hit count: 169

Filed under:
|
|

I've added functionality to an application that prints out a bunch of information to a FixedDOcument and sends this off to the printer. This works just fine, however the request is that there be an in application function that emails the document using OUtlook and its here that I come unstuck. I'd very much like to just reuse the class that makes the fixed document for printing to generate the text for email, but I'm struggling to do this.

I've tried the following...

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
MailItem email = (MailItem)(oApp.CreateItem(OlItemType.olMailItem));
email.Recipients.Add("[email protected]");
email.Subject = "Hello";
email.Body = "TEST";
FixedDocument doc = CreateReport(); //make my fixed document

//this doesn't work, and the parameters it takes suggest it never will
email.Attachments.Add(doc, OlAttachmentType.olByValue, 1, null); 
email.Send();

I can't help but think I'm on completely the wrong tack here, but I don't really want to have to write a bunch of new text formatting (since email.Body only takes a string) when I've already got the content formatted how I want it.

Note that the content is all textual, so I don't really care if it gets sent as an attachment or as text in the emails body. Ideally if its sent as an attachment it won't be saved anywhere permanently.

Any pointers?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf