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.ConnectSSL("imap.server.com");       // or Connect for non SSL/TLS
    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));

        string subject = email.Subject;
        string text = email.GetBodyAsText();
    }
    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.ConnectSSL("pop3.server.com");       // or Connect for non SSL/TLS
    pop3.UseBestLogin("user", "password");

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

        string subject = email.Subject;
        string text = email.GetBodyAsText();
    }
    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.From.Add(new MailBox("from@example.com"));
builder.To.Add(new MailBox("to@example.com"));
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.SetFileName("document.doc", guessContentType: true);

IMail email = builder.Create();

using(Smtp smtp = new Smtp())
{
    smtp.Connect("smtp.server.com");       // or ConnectSSL for SSL/TLS
    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.