Automated processing of an Email in C# - c#

Similar question as this one but for a Microsoft Environment.
Email --> Exchange Server -->[something]
For the [something] I was using Outlook 2003 & C# but it feels messy (A program is trying to access outlook, this could be a virus etc)
Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace objNS = objOutlook.GetNamespace("MAPI");
objNS.Logon("MAPIProfile", "MAPIPassword", false, true);
Is this the best way to do it? Is there a better way of retrieving and processing emails in a Microsoft environment???

This library provides you basic support for the POP3 protocol and MIME, you can use it to check specified mailboxes and retrieve emails and attachments, you can tweak it to your needs.
Here is another library, this one is for the IMAP protocol, it's very basic but also allows you to fetch complete messages, including attachments...

I've been happy with the Rebex components which provide IMAP access. Of course you need to ensure your Exchange administrators will open an IMAP port on your Exchange servers.

Using IMAP is a way to go. You can use Mail.dll IMAP component:
using(Imap imap = new Imap())
{
imap.Connect("imap.company.com");
imap.UseBestLogin("user", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.Unseen);
foreach (long uid in uids)
{
var eml = imap.GetMessageByUID(uid);
IMail message = new MailBuilder()
.CreateFromEml(eml);
Console.WriteLine(message.Subject);
Console.WriteLine(message.Text);
}
imap.Close(true);
}
You can download it here: Mail.dll email component.

I am trying http://csharpopensource.com/openpopdotnet.aspx, it have been recently updated and it is not bad. It lack good documentation but it also work with gmail/ssl.

Related

Voting Option Forward response to email Interop

I am trying to use c# Microsoft Outlook Interop to send an email with voting options. The only issue is that I want to not receive the response but rather the responses be sent to another email address (not mine).
Currently my code sends the voting responses to myself which is not what i want. I want to send it to a given email that I provide in string format.
This is my existing code:
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mail = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mail.Body= "hi";
mail.VotingOptions = "Cheese;Combo;Maybe;";
mail.Recipients.Add("abc#gmail.com");
mail.Send();
Use MailItem.ReplyRecipients.Add.

How do I send an email from a WinRT/Windows Store application?

I am developing a Windows Store Application (Windows 8).
I have a need to send emails based on data and address stored in the application data and without the need of the user to type it the data or the address.
What would be the right/easy way to implement it?
EitanB
You can try with
var mailto = new Uri("mailto:?to=recipient#example.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.");
await Windows.System.Launcher.LaunchUriAsync(mailto);
The correct way would be to use Sharing. Your app should create an HTML document or Text and share it. The user would select Mail from the Share charm and the HTML/Text would become the body of the email.
See here for more info...
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh973055.aspx
This is the correct syntax to use for a mailto: link (unlike the other examples above with a mailto: which are incorrect..)
var mailto = new Uri("mailto:yourname#email.com?subject=" + subject + "&body=" + body);
await Launcher.LaunchUriAsync(mailto);
The problem with the mailto: method is if the user has no client program associated with mailto: nothing will happen.
The most reliable method to use is a web service or WCF service of some sort. Using the Share Charm while considered the 'correct' way on Windows 8, is not neccessarily the best as the user may still have no email client installed, for example if they rely on gmail.com for their email.
If you are developping a Universal WinRT Windows Phone application, you could use the "Windows.ApplicationModel.Email.EmailMessage" namespace as the "Microsoft.Phone.Tasks.EmailComposeTask" namespace doesn't work on WinRT application.
Then, uses this code to create and launch a new email.
// Create your new email message.
var em = new EmailMessage() ;
// Add as much EmailRecipient in it as you need using the following method.
em.To.Add(new EmailRecipient("yourname#yourdomain.com"));
em.Subject = "Your Subject...";
em.Body = "Your email body...";
// You can add an attachment that way.
//em.Attachments.Add(new EmailAttachment(...);
// Show the email composer.
await EmailManager.ShowComposeNewEmailAsync(em);
I hope it will solve your (or other developers) problem.
Regards.
It's always possible to connect to an SMTP server and issue commands like HELO, MAIL, RCPT, etc. Of course you'll need an SMTP server to connect to. I use this on our corporate intranet to send emails.

Easiest way to read hotmail emails

I am looking for a library or a simple way to open a hotmail inbox and read new and old emails. A sample code would be much appreciated.
Thanks SOF.
I had the same problem and the gentleman from asp.net show me this link to go download openpop: http://hpop.sourceforge.net/
The link has a test project. But all I needed was:
Pop3Client pop3Client = new Pop3Client();
pop3Client.Connect("pop3.live.com", 995, true);
pop3Client.Authenticate("user", "password");
Message message = pop3Client.GetMessage(10);
string messageText = message.ToMailMessage().Body;
if you want to go with imap protocol ... this may help : using c# .net librarires to check for IMAP messages from gmail servers

Looking for a pop3 reader class in C# with SSL support

I was looking around and there is couple of projects but they all seem to be outdated,
should i use those? or is there a new out the box pop3 class that I can't find in msdn.
anyhow i'm not doing a client that needs to send out so no SMTP is needed, more like a bot that sorts out the emails and reads them., any ideas?
Cheers!
Take a look at Mail.dll POP3 client. It supports SSL, is easy to use, and supports parsing complex MIME structures:
using(Pop3 pop3 = new Pop3())
{
pop3.ConnectSSL("pop3.server.com");
pop3.Login("user", "password");
foreach (string uid in pop3.GetAll())
{
IMail email = new MailBuilder()
.CreateFromEml(pop3.GetMessageByUID(uid));
Console.WriteLine(email.Subject);
}
pop3.Close(true);
}
Please note that this is a commercial product that I developed
You can download Mail.dll here:
http://www.lesnikowski.com/mail/
I discovered OpenPOP on another thread, which seems to be my library of choice at the moment for this very task.
I built one a few years back that's posted on code project and it is dated (http://www.codeproject.com/KB/IP/NetPopMimeClient.aspx). If you are interested I can send you a copy of the latest source code which was never posted to CP.
I ended up using Dart Mail as a replacement for the solution I developed posted on CP. The main reason I ended up using Dart Mail is for the Mime Parsing facilities that it has which really ended up being the main problem with the solution I developed. IIRC Dart Mail is pretty reasonable and may be worth a look if you need something that is robust.

Suggestions for a .NET Pop3 Library

I am looking for a .NET Pop3 Email Library.
I need be able to read from a Pop3 account where I'll copy all the mail to a local database.
A paid library is fine
I found aspnetPop3 do anyone know if this any good
Any help would be a great help
I've tried a few, and settled on Lesnikowski Mail from http://www.lesnikowski.com/mail/. Its object model is a nice fit for how email really works; other libraries I used tried to hide the details but ended up just getting in the way. The Lesnikowski library was robust enough to work across hundreds of installations, talking to many different varieties of POP3 server.
The Indy library was an old favorite of Delphi developers for sockets programming, including SMTP and POP3. It's now been ported to C# and open sourced. You might want to check it out. One word of warning: there isn't a lot of documentation available, but most of the code is quite self-explanatory...
http://www.indyproject.org/SocketsCLR/index.EN.aspx
Our Rebex Secure POP3 might be fine for you. It's actively developed since 2006.
Following code shows how to to download all messages from the POP3 server and save them to the database:
// create client, connect and log in
Pop3 client = new Pop3();
client.Connect("pop3.example.org");
client.Login("username", "password");
// get message list - full headers
Pop3MessageCollection messageList = client.GetMessageList();
foreach (Pop3MessageInfo messageInfo in messageList)
{
// download message
MailMessage message = client.GetMailMessage(messageInfo.SequenceNumber);
// store it to the database...
// depends on your DB structure.
// message.Save(stream) or message.ToByteArray() would be handy
...
}
client.Disconnect();
I can recommend http://www.chilkatsoft.com/ and their mail components.
Not only will it allow you to send out email (plain text/encrypted/html) it also has POP3/IMAP components. There are tonnes of examples in a number of different languages and they are great on support if you should need it.
It also has a 30 day free trial (full funationality)
MailKit.Net, the official Microsoft replacement for SmtpClient also has support for Pop3 and Imap. It can be downloaded as a nuget package.

Categories

Resources