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.
Related
I'm trying to find a way (in C#) to read a txt file in which there's a name written, and then the program should search in the address book (of Outlook or even the others address books of Windows) and resolve that name as an SMTP address.
Via OOM i can easily reach Exchange format mail addresses, but i don't know what to do with these, since i build my mail as a MailMessage object, that only supports SMTP addresses.
I've tried different ways:
1-Microsoft.Communications.Contact:
`ContactManager cm = new ContactManager();`
`List<Contact> contatti = (List<Contact>)cm.GetContactCollection();`
The second row cause me a NullReferenceException.
2-CDO library: i can't obtain anything, because it lacks some important classes such as AddressEntry.
3-MAPI library (CDO 1.2 downloaded from microsoft.com): is only full of interfaces, can't instantiate anything.
Any suggestions?
As Ben suggests, you might run into problems where the name you have is not unambiguous. You need to be prepared for this.
Apart from that issue you have two options here: Query AD for the information (using System.DirectoryServices or even better System.DirectoryServices.AccountManagement). From the entities returned, read the proxyAddresses property. This property contains the addresses of the user or contact.
If you are running Exchange 2007 or later, you can also use the EWS Managed API to resolve the name via Exchange. Use the ResolveNamed method: http://msdn.microsoft.com/en-us/library/exchangewebservices.exchangeservicebinding.resolvenames(v=exchg.140).aspx
EWS Managed API - Download: http://www.microsoft.com/download/en/details.aspx?id=13480
EWS Managed API - SDK: http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx
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.
I'd like to ask your help regarding having a Google Talk Bot that will communicate with my code on my server.
I have downloaded Jabber-Net from code.google.com, but the examples there are not enough... I am new to these technologies, and have no clue about:
How will client arrive to my server? where should I change [if any] DNS to my server?
Which server side library should I use?
From the examples I understood that I need to have a Desktop-app running in the background constantly, which doesn't make sense to me.
Does anyone has an example of some better references to understand this better?
[Sorry for my ignorance...]
I'm not sure if I understand what you ask correctly. If you're asking how to connect to chosen server, console sample shows how to do it simply, you basically fill out JID class.
Sample from Jabber-Net
JabberClient jc = new JabberClient();
JID j = new JID(jid);
jc.User = j.User;
jc.Server = j.Server;
jc.NetworkHost = networkHost;
jc.Port = port;
jc.Resource = "Jabber.Net Console Client";
jc.Password = pass;
jc.AutoStartTLS = TLS;
jc.AutoPresence = initialPresence;
If you want to create your own server, there's a library (also running under .NET) called agsxmpp, it allows to create both, server and client, it's open source on MIT/GPL license afair. I don't know if jabber-net enables this feature. On the other hand, there are plenty of free jabber-server if you don't want to just use one of "public" ones, so it may be worth to consider just using something that is ready to be launched.
There's a console sample in the project, you don't need desktop-app (if this is what you were asking?), so you can write service, console app or anything else.
Here's a recent post that shows an example of replying to incoming messages on Gtalk using .NET
I am creating eml's and saving them to a directory using procedure mentioned over here.
I want to know how to send these eml files?
I tried using SMTPClient class's object but it takes MailMessage object as its parameter and I couldn't find and way to create an object of type MailMessage using these saved eml files.
Loading an EML file correctly is not as easy as it looks. You can write an implementation working in 95% cases within few days. Remaining 5% would take at least several months ;-). I know, becase I involved in developing one.
Consider following dificulities:
unicode emails
right-to-left languages
correcting malformed EML files caused by well known errors in popular mail clients and servers
dealing with S/MIME (encrypted and signed email messages)
dealing correctly with several methods of encoding attachments
dealing with inline images and stylesheets embedded into HTML emails
making sure that it parses correctly a MIME torture message from Mike Crispin (coauthor of Mime and IMAP RFCs)
making sure that malformed message will not result in buffer overun or other application crash
handling hierarchical messages (message with attached messages)
making sure that it handles correctly very big emails
Maturing of such parser takes years and continuous feedback for it's users. Right now is no such parser included in the .NET Framework. Until it changes I would sugest getting a thrid party MIME parser from an established vendor.
Following code uses our Rebex Secure Mail component, but I'm sure that similar task could be replicated easily with components from other vendors as well.
The code is based on Mail Message tutorial.
// create an instance of MailMessage
MailMessage message = new MailMessage();
// load the message from a local disk file
message.Load("c:\\message.eml");
// send message
Smtp.Send(message, "smtp.example.org");
Use EMLReader to retrieve data from .eml file. It contains all the data you need to create a MailMessage object like From, To, Subject, Body & a whole lot more.
FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite);
EMLReader reader = new EMLReader(fs);
fs.Close();
MailMessage message = new System.Net.Mail.MailMessage(reader.From, reader.To, reader.Subject, reader.Body);
If you're a Microsoft shop and have an Exchange server anyway, then there's another solution which is much, much easier than everything else suggested here:
Each Exchange server has a pickup directory configured out of the box.
By default, it's %ExchangeInstallPath%TransportRoles\Pickup.
You just copy the .eml files to that directory, and Exchange automatically will send the mails.
Read this TechNet article for more information:
Pickup directory and Replay directory
As others demonstrated, EML is just not a good way to serialize a mail message. You might be better off by saving your mails in another format. While there are several serialization engines in the .Net framework to serialize any object, you might also consider just saving the components of your mails, like addresses, body, files to be attached in base64, in an Xml file of your own design.
Below is an example to get you started:
<?xml version="1.0" encoding="utf-8"?>
<mail>
<to display="Thomas Edison" address="tedison#domain.com" />
<body>
Hi Thomas,
How are you doing?
Bye
</body>
<attachment name="MaryLamb.wav">
cmF0aWUgYWFuIGluIFBERi1mb3JtYWF0LiBEZSBmYWN0dXVyIGlzIGVlbiBvZmZpY2ll
ZWwgZ2VzaWduZWVyZA0KZG9jdW1lbnQgdmFuIEV1cm9maW5zIE9tZWdhbSBCVi4gRGUg
c2lnbmF0dXJlIGt1bnQgdSB2ZXJpZmnDq3Jlbi4NCg0KVm9vciBoZXQgdmVyaWZpw6ty
...
</attachment>
</mail>
Added advantage would be that, unlike with creating EML, you do not need the smtpClient to build the concept mail files.
Xml is extremely easy to create and parse in C#.
You did not tell the rationale of saving EML's. If long term archival would be a goal, xml might have an advantage.
Do What i did ... give up.
Building the MailMessage object seems to be the focus i have a similar questions outstanding on here too ...
How do i send an email when i already have it as a string?
From what i've seen the simplest way to do this is to use a raw socket to dump the entire .eml file contents up to the mail server as is and let the mail server figure out the hard stuff like from, to subject, ect by parsing the email using it's engine.
The only problem ... RFC 821 ... such a pain, i'm trying to figure out a clean way to do this and read mail already in the mailbox quickly too.
EDIT:
I found a clean solution and covered it in my thread :)
How do i send an email when i already have it as a string?
You can do this with Windows Server’s built-in SMTP server, the same way as in the previous answer using Exchange.
Drop the .eml file to C:\inetpub\mailroot\Pickup and the raw message will be sent (local or remote).
You can forward messages by simply inserting a line in the top:
To: email#address.com
You can manipulate the mail header further if you require.
For the records:
In Nuget Packager Console write:
Install-Package LumiSoft.Net.dll
Then in your Code:
using (FileStream fs = new FileStream( cacheFileName, FileMode.Open, FileAccess.Read ))
using (LumiSoft.Net.SMTP.Client.SMTP_Client client =
new LumiSoft.Net.SMTP.Client.SMTP_Client())
{
client.SendMessage( fs );
}
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.