Reputation: 131
I am trying to simply retrieve a outlook email file name along with its local path, and open that .msg file via outlook. Is there a method to achieve such? or is it entirely impossible?
I DO NOT need to read the contents of the .msg file. I just need to open it so the end user can view the saved email file.
I did the following but it does not work at all.
try {
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
string filePath = MapPath("~\\path\\filename.msg"); var item = app.Session.OpenSharedItem(filePath) as Microsoft.Office.Interop.Outlook.MailItem;
string body = item.HTMLBody; int att = item.Attachments.Count;
} catch (Exception ex) {
Global.Log.Error(ex.Message, ex.InnerException);
}
Upvotes: 0
Views: 2614
Reputation: 49397
There is only one possible way - automate Outlook from a JS code which is run inside IE or use the mailto
protocol:
var link = "mailto:[email protected]";
// In addition to this you can add subject or body as parameter .
// For e.g.
// "mailto:[email protected]?subject=test subject&body=my text"
window.location.href = link;
The Considerations for server-side Automation of Office article states the following:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
In such cases, you may consider using EWS if you deal with Exchange profiles/accounts only. Also, you may consider using a low-level API on which Outlook is based on - Extended MAPI or just any third-party wrapper around that API.
Upvotes: 1