简体   繁体   中英

How to handle User Access Control when using MAPI in .NET

I've used MAPI to create emails with attachments from my application and it works very well on XP and Vista (without UAC). Of course, if you have UAC enabled, it just doesn't work (though it gives no errors, and doesn't prompt the user for permission to continue).

I've done a bunch of reading and have found a lot of differing ideas:

  • Require Admin privileges for the app
  • Require some form of elevated privileges for the app
  • Create a COM object for the small portions of code that require elevation
  • Get the OS to prompt the users asking them if they want to continue.

I'm wondering what SO Users would do given that I really only need elevation for one or two functions. I'm looking for the minimal amount of pain here (I don't do COM, but I can P/Invoke with the best of them...), and I'm working in .NET 2.0 (it's a legacy app).

EDIT: I agree that elevating the whole app isn't a great idea given that only part of it needs the eleveation, but my thought had been that might be easier in the long run than trying to elevate only part of it.

Also, I'd rather stay away from the .NET SMTP solution, since my goal is simply to create a message and with an attachment, but display it to the user so that they can add more text and send it at their leisure...

If you can give up MAPI in favor of the more general SMTP , you can use .NET's System.Net.Mail.SmtpClient class. Together with the MailMessage class, you can add attachments and send messages via any willing SMTP server.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM