mhesabi
mhesabi

Reputation: 1140

C# Create Outlook task without using office interop

I need to create outlook tasks and add them to users task folder in my Asp.net MVC application, and after some researches I found out that using office interop is and option but is not a good choice.
so I need to know what are other options to accomplish this goal?

Upvotes: 0

Views: 2167

Answers (2)

mhesabi
mhesabi

Reputation: 1140

After more searches I decided to use EWS. so here is what I implemented to create tasks using exchange web service:

var exchange = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
exchange.Credentials = new WebCredentials("username", "password", "domain");
exchange.AutodiscoverUrl("[email protected]");

// see #1
// exchange.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, [email protected]");

var task = new Task(exchange);
task.Subject = "foo";
task.Body = new MessageBody("bar");
task.Status = TaskStatus.InProgress;
task.StartDate = PurchaseOrder.OrderDate;
task.DueDate = PurchaseOrder.DeliverDate;
task.Save();

// see #2
// task.Save(new FolderId(WellKnownFolderName.Tasks, "[email protected]"));

according to this article you can save tasks in the user's task folder that exchange service is configured with.

#1: unless you have impersonate permission
or
#2: your target user delegated tasks to you.
in my case I seems to use #2 ...

Upvotes: 0

Eugene Astafiev
Eugene Astafiev

Reputation: 49397

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. Read more about that in the Considerations for server-side Automation of Office article.

As a workaround you may consider using a low-level API on which Outlook is based on - Extended MAPI or any other wrapper around that API such as Redemption.

In case if you deal with Exchange mailboxes only you may consider using EWS, see EWS Managed API, EWS, and web services in Exchange for more information.

Upvotes: 1

Related Questions