MAPI in .NET 5? - c#

I want to open the default email client on the computer with presetted values for from, to, subject, body and attachments.
However, MAPI32.DLL has been deprecated many years ago by Microsoft and does not work with .NET 5 64bit applications.
I allready tried many different things but I cannot come up with a solution.
What did I try?
mailto: (doesn't support attachments)
SimpleMapi (deprecated and does not work within .NET 5/Core 64bit applications)
Writing the mail as .eml file and open it with the default mail program
Does anybody else have an idea, how I could achive this?
The target mail client is Tobit David.
Thanks!

Related

Printing to Receipt Printer from Web Application

This is more a question if I am taking a 'wrong path' to accomplish the task.
I need to print Data to Receipt Printers from Web Application.
Based on what I understand from various posts on net, it seems best option would be to create something like a Print Server (not sure about the name). This will be C# desktop application running as a service. I am planning to put messages in queue and Print Server to pull messages from queue and print it to reconfigured LAN printers. I will be using POS.NET to connect to POS devices.
Added advantage (to using Javascript/pdf solutions) is that I can enhance the same "Print Server" to send information to display system. The message system could be decoupled to be on cloud so as to print in a different geographical area, like warehouse.
If I target Framework 3.5 for the service, I can get rid of POS.NET issues with Framework 4.0 plus versions.
Am I reinventing something that is already available in .Net or possibly an open-source application?
I found these kind of similar questions
How to print from web application to receipt printer?
Configuring a POS printer for remote printing
which were helpful but did not answer my question in full.
I had a to do exactly this, and after many hours of searching, I could not find anything. I achieved this by installing Thunderbird (any email client will do) and send the receipt via email to the account linked up to that client, I then setup a rule on the email client to print out anything it recieved.

How do I load prepared message, with attachments, into user's default mail client?

How do I load prepared message, with attachments, into user's default mail client?
I went looking around for answers to that, and found:
Using Process.Start() with a "mailto:" url won't work, because mailto: doesn't support attachments (except in Outlook, and I can't rely on Outlook being the default client.)
This Code Project MAPI wrapper won't work, because it apparently blocks the app.
Then there's this MAPI Wrapper, which apparently does not block the app, but it changes the current directory, and that breaks a number of things in our app, some of which are running in different threads, so I can't rely on just changing it back.
And after trying out the above, and discovering the current directory issue, I ran across this blog post, which blamed the issue on the MAPI stub library,
And that directed me here, which pointed out that the MAPI stub library is deprecated.
Which leaves me asking:
Is there a way, in a C# application, to create an email message that includes attachments, and load it into the user's default mail client, that does not depend upon the client being Outlook, doesn't block the UI of the app while running, doesn't change the current directory of the app out from underneath it, and doesn't rely on deprecated and soon-to-be-removed system libraries?

Creating and showing e-mail on Windows with maximal e-mail client compatibility

I need to create an executable that can be called from the command line which will create an e-mail, attach files to the e-mail and show the e-mail to the user so that they can complete the e-mail and send it. This should be done in the e-mail client that the user has configured as their default.
This needs to work for as many e-mail clients as possible. The ones I'm aware of that are used most are Outlook 2007-2010, Outlook Express, Windows Live Mail and Thunderbird. I'll target .NET 2.0 so that it does not require a newer .NET to be installed if the user is using Vista.
Simple MAPI is capable of doing the above, but Outlook 2007+ does not support it. All the other mail clients on the list do support Simple MAPI. I get the impression that Outlook is the only client that uses Extended MAPI and that Extended MAPI is tricky to use, so it's better to just use the Outlook COM API instead of Extended MAPI.
First the program will look for Outlook and use the Outlook COM API to perform the above if Outlook is available. I'll implement this component in VB and use late binding so that I'm not compiling against a specific version of Outlook. Then, if Outlook is not found it will fall back to Simple MAPI and attempt to use it.
Because of all this decision-making in the code I'll make this program log its activity so that we can debug what is happening on the user's machine when it doesn't work.
Will this approach work? Do you know a better approach? My goal is to maximize compatibility.
EDIT
It looks like Outlook 2007+ does support Simple MAPI, but if you're running the 64 bit version then a 32 bit executable can't call it. I'll stick with the above plan for that reason.
Outlook 2007 supports Simple MAPI just fine.

C# / Exchange EMail Client

I need to create a very simple c# Windows Service to listen for, and process email wth special subject lines. I already have the code that process these emails working well. For ease of development, I just packaged the code in an "Outlook Addin" on my own machine, running under my own email account. Works great.
Now that it's working, I need to move this to the server. I have a special email account setup on the Exchange Server for this purpose. I really don't want Outlook running on the server. Is there some other way to login to this email account and listen for email from my Windows Service without using the Outlook client?
Thanks!
It sounds like your code is closely tied to Outlook, so you may have to change your approach for the server. I faced exactly the same problem last year and considered the following options :
CDO (not supported by Microsoft with .NET due to some strangeness when running in process)
WebDAV for Exchange 2003
Web Services for Exchange 2007 (great example in the link)
You also need to ask yourself - do you actually need your program to check the mail server? I couldnt use any of the above options so ended up having one of the mail admins set up an exchange rule that dropped the emails/attachments into a special folder on the server. I could then process the files at my leisure. Worked extremely well and much easier to maintain than directly interrogating the mail server through code.
If your exchange admin has enabled it you can use IMAP or POP3 to connect to the server.
You can also use MAPI to connect as well.
You can find a number of libraries (free and otherwise) for doing all three.
I have had good experience with MailBee IMAP but there are definitely free alternatives if you only need to do some simple functionality.

How should I go about getting and processing an (Exchange) email attachment?

I need to get a zip file from an email attachment, unzip it and copy it somewhere.
What would be the way I should go about it?
I'm currently googling around things like 'Exchange API' and 'processing email attachments' and kind of hoping this kind of thing has been done before.
The environment will be Windows and Exchange 2003, and any coding will preferably be in C#.
I had to do this some time ago, and the best way is to use WEBDAV. Every mail item can be referenced like a URL.
If you check out this blog post on WEBDAV, it should show you the way.
I did this in the end using Redemption I had a couple of problems, hence the linked question but got there in the end.
You do need to have the Outlook client installed, and you need full mailbox rights (not just read) on whatever mailbox you are trying to access.
This question, Read MS Exchange email in C# asked a couple of weeks after mine got some good answers as well.
Assuming you want to do this in .NET you will either have to write or purchase a POP3 or IMAP4 class library to communicate with the Exchange server.
Here is one example of a POP3 client from CodeProject:
http://www.codeproject.com/KB/IP/despop3client.aspx

Categories