I am working on an application which requires a feature to allow user to send emails . I looked for SMTP but it requires password ( and i guess it should be used for organization level emails with one time configuration) . I also looked for MAPi using this repo but i could not make it work
https://github.com/PandaWood/Simple-MAPI.NET
So is there a way to achieve this , specifically opening default mail application of the user with attachment.
Thanks
Here is what MS states for the Simple MAPI:
The use of Simple MAPI is discouraged. It may be altered or unavailable in subsequent versions of Windows.
Simple MAPI is a set of functions and related data structures you can use to add messaging functionality to Windows-based applications written in C, C++, or Visual Basic. You can use pinvoke to call Simple MAPI functions from your application, see Writing cross platform P/Invoke code for more information.
Also you may consider using the mailto protocol or just automating Outlook (if it is installed on the system). That's the most easiest way.
If you deal with Exchange profiles you may also consider using EWS or Graph API. Read more about EWS in the Explore the EWS Managed API, EWS, and web services in Exchange article.
Related
I have been tasked to convert an Outlook Distribution list to a CSV file.
I have seen some examples online but I can’t find the COM reference.
Question:
Do I need to have Office installed to find the reference?
Does a subscription to Office 365 work as well?
I’m developing this project with VS 2022, and .NET 6
Thank you!
First of all, there are several ways to get get distribution list members. If you deal with Exchange profiles only you may consider using EWS, see Expanding a distribution list by using the EWS Managed API 2.0 for more information.
Another possible option is Graph API. Distribution lists are actually represented by the group entity in Microsoft Graph, so in your case you should be able to use the id returned from your people search in the following to get the group/DLs members
GET https://graph.microsoft.com/v1.0/groups/{id}/members
You could just search for your DL by filtering on the group entity:
GET https://graph.microsoft.com/v1.0/groups?$filter=displayName eq 'DL_NAME'
The people API is really about people that you communicate with most often - and it includes users, groups and contacts.
Both EWS and Graph API don't require installing anything on the end-user machine and can be used from the server-side or service software.
The last option is automating Outlook. In that case you need to install the desktop editions of Outlook to get a COM server registered for the application. As soon as COM server is registered you can add an Outlook COM reference.
Does a subscription to Office 365 work as well?
Yes, if it allows installing Outlook on your machine.
Hopefully a simple question. In the Exchange Powershell API, there are functions such as "get-casmailbox" to set a mailbox to be accessible via OWA, etc. I am trying to integrate this type of functionality in to a C# program, and it is absurd to call Powershell in C# just to interact with Exchange.
I have successfully added the EWS API, but cannot find such functionality like get-casmailbox.
Is there an alternative, or am I stuck with doing get-casmailbox and set-casmailbox in Powershell only?
I think it is absolutely okay to use Powershell as it is the only interface to administer Exchange Settings in a reliable way.
You could look at the protocolSettings Attribute of the user - these settings are stored there. But I absolutely do not recommend to change them directly. (Although it might work)
Enjoy -tom
I wanted to write a class library to watch over an inbox for new mails with a particular subject and download the attachment. The end goal is to publish the library in Azure as a WebJob / API with the ability to use this library to host it on-premise. We are also planning to integrate this with a workflow functionality that we have already developed. I have found the following stuff online but have some limitations with each.
Logic Apps has a connector but I will have to write something separate for on-premise.
Office Rest APIS has several APIs exposed but all of these has redirect URL for logging user in. I wanted something like a service principal in this case which can call the URL directly without redirection to MS login page.
Other articles uses Interop DLLs which I guess would create problems when hosting as a WebJob as I have seen in the past.
Please help me with the what would be the best approach and if there is a library built in for this which I'm not able to find.
Thanks a lot in advance.
The Microsoft Graph API would be a pretty good place for getting user emails.
Here is the operation you are looking for: https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_list_messages
So you will need to make a request to something like:
https://graph.microsoft.com/v1.0/users/user#company.com/messages
And you can do this with a service principal. You will need the Mail.Read app-only permission (Read mail in all mailboxes). This will require you to be an Azure AD admin to consent. You can find details on the permission scopes here: https://graph.microsoft.io/en-us/docs/authorization/permission_scopes.
Oh, and there are SDKs so you don't need to write all the stuff yourself: https://graph.microsoft.io/en-us/code-samples-and-sdks
my .NET application is a WPF desktop application responsible for sending e-mail with classic SASL mechanism and/or older one (POP-before-SMTP).
A end-user can select any SASL authentication mechanism on the GUI configuration of this application.
As a developper , I was wondering what where the gain(s) and cost of implementing the oAuth2.0 authentication mechanism availability?
What does the end-user benefit from having this authentication mechanism option available?
The end-user can provide itself with a Gmail account
The biggest advantage is that they don't need to create yet another account and another password they now have to remember / protect. OAuth2 is also a pretty well defined standard used by all major providers : Google, Microsoft etc.
From a developer point of view, there are libraries which can take away the pain of coding the mechanism yourself however I do advice to at least read and understand how it works down to the finest detail.
I have my own article on OAuth2, you're welcome to check it put and should be able to describe in detail ho to create your own implementation using standard libraries: https://eidand.com/2015/03/28/authorization-system-with-owin-web-api-json-web-tokens/
how do I send Twitter updates in C# but without the need of OAuth?
The reason is, is because I heard that Twitter limits how many Tweets one can send, and I am planning to send a lot.
The officially supported means of sending a tweet via a third party application is by using the REST API twitter provides. This does require clients to use OAuth to authenticate.
If you don't want to deal with the API directly you might consider using a library which wraps the official API. I can't personally recommend any particular library as I have not used a Twitter library in a long while, however Twitter does provide a list of API implementations which may interest you.
It is possible that one could use the WebBrowser control to interface with twitter by website form fields with values passed to your application through your application's user interface.
Doing this is not advised for the following reasons:
It's officially unsupported and against Twitter's terms of use. This method depends on your application parsing the twitter user interface in order to find and populate form feilds. The names of these feilds may change at any tine without notice.
It will not circumvent the rate limiting. Twitter's rate limiting is enforced at the server side and the web interface is not likely to be immune to this rate limiting.