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

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

Related

MAPI in .NET 5?

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!

Prevent users from stealing password using WireShark and such

I have a Windows Forms Application which communicates with an FTP Server everything works flawlessly, except that the user is able to use WireShark, filter for FTP and easily get full access to my FTP Server. I really need a way to prevent this, but the only idea I could come up with was to use SFTP or FTPS. The problem is that currently I'm using edtFTPnet free and couldn't find any free SFTP or FTPS class to implement on my current code.
What would be the best approaches (free or extremely low cost) to solve this problem?
There are a few free SSH libraries: (SharpSSH, SSH.Net for example)
The problem is you're relying on someone not looking at the password. Instead, issue your clients their own credentials. Be it, username & passwords per user or issue the client a certificate.
Also, Daniel's advice is sound; make sure that if they DO get the password, there's little to no damage that can be done
I think you are going the wrong way here.
You don't really have control over the client side, so don't bother trying to secure it.
Instead, secure your server.
Make sure that the account used by your application only has limited rights on the FTP server. For example, you could disallow DIR or constrain him to a certain directory.

How to send Outlook tasks requests by mail without Outlook?

I need to replicate the Outlook feature/functionnality to send some tasks requests to someone (see here) but with mails sent from a webserver using ASP.NET C# and without Outlook installed on the webserver (thus using outlook automation is not possible).
I already check what are the possiblities to do this, and it seems a common way to send tasks to someone is to generate an .ics file in iCalendar format, and include that file to the mail (see this stackoverflow question).
It works great, however there is no equivalence of tasks sent by outlook :
Events (VEVENT) have a start date and end date (like a task) but no "completion" field (which make sense since it is an event, not a task).
Todos (VTODO) have only a due date, no start date or end date and it is not supported by outlook.
I checked myself what Outlook exactly send in a mail containing a task request : It include a winmail.dat file (with content-type:application/ms-tnef) encoded as Base64. Inside that file (which is a binary file) there is a reference to IPM.TaskRequest which seems to be what i need.
I checked the web and found some TNEF parsers, but i need the oposite : to generate from C# code a TNEF file that would contains a task request. I would like to know if there is a way to do that. Using a library (free or not) is not an issue.
Even if outlook were installed on the web server, outlook automation on a server is generally a bad idea.
However, have you looked at Exchange Web Services? It provides a complete object model to integrate with outlook. Obviously it's tied to outlook (unlike ics), but it does seem to fit your use case.
EWS overview: http://msdn.microsoft.com/en-us/library/exchange/dd877045%28v=exchg.140%29.aspx
Working with tasks: http://blogs.msdn.com/b/dhruvkh/archive/2012/04/06/working-with-tasks-using-exchange-web-services.aspx

How to build a ftp server

I'd like to build an home FTP SERVER - that will store all my files and the rest of my computers will upload and download files to and from it.
I don't like to start from scratch, do you know of a c# ftp server implementation?
Can you give me some guidelines of where to start what I should know etc?
Based on a few of your comments why do you not just enable the FTP server through IIS on one of your computers in your network, or just enable file sharing? These things are already partof/included in Windows at your disposal.
You say you don't want to start from scratch, so use something that's already been through the pain: http://filezilla-project.org/
The FTP RFCs for the protocol specification and the System.Net.Sockets namespace.
And read as much as you can on security (mailing list, bulletins, books, ...) because you can very easily leave holes for anyone to get to your files.
(I don't know of any FTP libraries beyond what .NET includes (I've not needed any FTP), but there are also third party networking component libraries that may include richer functionality. You'll likely still need to understand what's going on for debugging.)
You first need to understand the protocol: RFC959
Here a basic server in C#: http://www.c-sharpcorner.com/UploadFile/ivar/FTPServer12072005041005AM/FTPServer.aspx
Read on security...

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.

Categories