I wonder if it's possible with the .net framework or Microsoft.Office.Interop.Outlook to load an email message (*.msg), do a search and replace and send it from C#.
It's all happening on the server so Outlook cannot be installed.
What I've tried
the Redemption library but somehow it loses the images inlined in the template and can't figure out to remedy this
Using Microsoft.Office.Interop.Outlook
Application objOutlook = new Application(); objOutlook.CreateItemFromTemplate("c:\temp\..",)
But it expects as it second parameter an outlook folder, I can't give it a file path where it will save to
I'm thinking to switch to regular txt files instead of C# but maybe someone did this already
Update 1
This is the redemption code I tried. The problem is that the formatting and image (of a signature is not preserved)
using Interop.Redemption;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Replace(@"mailnonunicode.msg");
Replace(@"mailunicode.msg");
Replace(@"mailtemplate.oft");
}
static void Replace(string cTestharnessKmailMsg)
{
RDOSession rdoSession = new RDOSession();
RDOMail messageFromMsgFile = rdoSession.GetMessageFromMsgFile(cTestharnessKmailMsg);
messageFromMsgFile.Body = messageFromMsgFile.Body.Replace("abc",
"xyz");
messageFromMsgFile.Save();
}
}
}
Update 2 / Solution
If you want to preserve the formatting, you need to work with HTMLBody or RTFBody properties, not with the plain text Body.