views:

1216

answers:

4

I'd like to write a service that periodically checks a POP3 account for new messages and based on custom business logic forwards the messages to an appropriate "To", and possibly changes the "From" as well. I might need to keep some messages on the server until certain conditions are ready for them to be forwarded.

I found a sample using Chilkat .NET components that might work: http://www.example-code.com/csharp/pop3_forwarder.asp

My question is: Are there any other examples of this in the .NET space using any other components?

Thanks!

A: 

I implemented something very similar using MailBee's IMAP, POP and SMTP .NET components.

They're not free, I'm afraid, but I've found them to be pretty solid, and AfterLogic's support is fast.

There's also the free (including source code) LumiSoft Mail Server, that has POP3 relay support to collect messages from a POP3 server and manage them from there, you could adapt that? (It's written in C#, is nice to work with and upgrades cleanly to VS2008). I've had no problems with that either.

Matthew Brindley
+3  A: 

The following SO questions/answers might help finding components for the POP3 part of your porject:

And you can use SmtpClient in System.Net.Mail for sending the mails:

f3lix
Thanks for the pointer. I found Peter Huber's "POP3 Email Client with full MIME Support" at http://www.codeproject.com/KB/IP/Pop3MimeClient.aspx and it looks like it will work well. It has an easy api, and it downloads each message from a POP3 server as a "System.Net.Mail.MailMessage".
Troy
...then I can modify the message according to my needs and then forward the MailMessage on using System.Net.Mail.SmtpClient.
Troy
A: 

Try Mail.dll .NET email component. It has SSL support, POP3 and SMTP clients.

using(Pop3 pop3 = new Pop3())
{
    pop3.Connect("mail.host.com");    // Connect to the server 
    pop3.Login("user", "password");

    foreach(string uid in pop3.GetAll())
    {
        // Receive mail
        IMail mail = new MailBuilder()
   .CreateFromEml(pop3.GetMessageByUID(uid));
        Console.WriteLine(mail.Subject);
    }
    pop3.Close(true); 
}

You can download it here

Pawel Lesnikowski
A: 

C#Mail is pretty easy to use.
Get mail text data by using Pop3Client class and send e-mail by using SmtpClient class.
You can send exactly same text data with C#Mail library.

---Sample Code--------------------------------------
using (Pop3Client cl = new Pop3Client())
{
    cl.UserName = "MyUserName";
    cl.Password = "MyPassword";
    cl.ServerName = "MyServer";
    cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
    cl.Authenticate();
    ///Get first mail of my mailbox
    String text = cl.GetMessageText(1);
    ///Use ssl and plain authenticate
    SmtpClient cl = new SmtpClient();
    cl.ServerName = "smtp.csharp.com";
    cl.Port = 25;
    cl.UserName = "my name";
    cl.Password = "**********";
    cl.HostName = "MyComputer";
    cl.AuthenticateMode = SmtpAuthenticateMode.Plain;
    cl.Ssl = true;
    SendMailResult rs = cl.SendMail("mail from", "to", "cc", "bcc", text);
}
-------------------------------------------
Higty