How to handle user access control when using MAPI in .NET.

I have used MAPI to create emails with attachments from my application and it works fine on XP and Vista (no UAC). Of course, if you have UAC enabled, it just doesn't work (although it doesn't give any errors and doesn't ask the user for permission to continue).

I did a bunch of reading and found many different ideas:

  • Require administrator rights for the application
  • Require some form of elevated privilege for an application
  • Create a COM object for a small piece of code that requires height
  • Get the OS to prompt users by asking them if they want to proceed.

I'm wondering what SO users would be doing, given that I really only need the height for one or two functions. I'm looking for minimal amount of pain here (I'm not doing COM, but I can P / Invoke with the best ones ...) and I'm working in .NET 2.0 (it's a legacy app).

EDIT: I agree that raising the entire application is not a great idea, given that only part of it needs to be elevated, but I thought it might be easier in the end than trying to raise only part of it.

Also, I would rather steer clear of the .NET SMTP solution, as my goal is to simply create a message and attachment, but display it to the user so they can add more text and send it at their leisure ...

0


source to share


1 answer


If you can ditch MAPI in favor of more general SMTP , you can use the .NET System.Net.Mail.SmtpClient class . With the MailMessage class , you can add attachments and send messages through any SMTP server .



All available in good old .NET 2.0 as managed code - no need for p / invoke or COM. Examples on reference pages.

0


source







All Articles