Click or drag to resize

Mail.dll - How to start

After installation, this class reference, C# and VB.NET examples can be found in your Start menu.

Go here for licensing and general help, and here for ordering.

Note Note

If you need help, please visit our technical Q&A forum. You can find many samples online.

Add reference and namespaces

First you have to add reference to Mail.dll to your project. See MSDN how to. Then add all namespaces you need:

// C#

using Limilabs.Client.IMAP;
using Limilabs.Client.POP3;
using Limilabs.Client.SMTP;
using Limilabs.Mail;
using Limilabs.Mail.MIME;
using Limilabs.Mail.Fluent
using Limilabs.Mail.Headers;
Receive emails from IMAP server

We connect to IMAP server using Imap class, then log in and acquire IMail object using MailBuilder class.

// C#

using(Imap imap = new Imap())
{
    imap.Connect("imap.server.com");       // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");

    imap.SelectInbox();
    List<long> uidList = imap.Search(Flag.Unseen);
    foreach (long uid in uidList)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));

        Console.WriteLine(email.Subject);
        Console.WriteLine(email.Text);
    }
    imap.Close();
}
Receive emails from POP3 server

We connect to POP3 server using Pop3 class, then log in and acquire IMail object using MailBuilder class.

// C#

using(Pop3 pop3 = new Pop3())
{
    pop3.Connect("pop3.server.com");       // or ConnectSSL for SSL
    pop3.UseBestLogin("user", "password");

    foreach (string uid in pop3.GetAll())
    {
        IMail email = new MailBuilder()
            .CreateFromEml(pop3.GetMessageByUID(uid));

        Console.WriteLine(email.Subject);
        Console.WriteLine(email.Text);
    }
    pop3.Close();
}
Send emails using SMTP server

You have to create IMail object. Use MailBuilder class or fluent interface, then connect to your SMTP server using Smtp and send your message.

// C#

MailBuilder builder = new MailBuilder();
builder.Html = @"Html with an image: <img src=""cid:lena"" />";
builder.Subject = "Subject";

MimeData visual = builder.AddVisual(@"c:\lena.jpeg");
visual.ContentId = "lena";

MimeData attachment = builder.AddAttachment(@"c:\tmp.doc");
attachment.FileName = "document.doc";

builder.From.Add(new MailBox("from@mail.com"));
builder.To.Add(new MailBox("to@mail.com"));

IMail email = builder.Create();

using(Smtp smtp = new Smtp())
{
        smtp.Connect("smtp.server.com");       // or ConnectSSL for SSL
        smtp.UseBestLogin("user", "password");

        smtp.SendMessage(email);                      

        smtp.Close();    
}
Samples online
Note Note

If you need help, please visit our technical Q&A forum. You can find many samples online.