Mail.dll - How to start

Mail.dll 3d box

Class reference, C# and VB examples were installed in your Start menu.

For frequent asked questions visit: www.lesnikowski.com/mail/faq.aspx

For ordering info goto: www.lesnikowski.com/mail/buy.aspx

How to use Mail.dll?
First you have to add reference to Mail.dll in your project. See MSDN How to.
Receive an email
We connect to your POP3 server, login and acquire ISimpleMailMessage object using SimpleMailMessageBuilder class.
using System;
using Lesnikowski.Client;
using Lesnikowski.Mail;
using Lesnikowski.Mail.Headers;
using Lesnikowski.Mail.Headers.Constants;

class Program
{
    static void Main(string[] args)
    {
        Pop3 pop3 = new Pop3();
        pop3.User = "lesnikowski";                  // Set user name and password
        pop3.Password = "password";

        pop3.Connect("mail.host.com");              // Connect to server and login
        pop3.Login();
        pop3.GetAccountStat();                      // Get account statistics

        SimpleMailMessageBuilder builder = new SimpleMailMessageBuilder();
        for(int i = 1; i <= pop3.MessageCount; i++)
        {
            ISimpleMailMessage simpleMail = builder.CreateFromEml(
              pop3.GetMessage(i)
              );
              
            // Write out email's subject
            Console.WriteLine(simpleMail.Subject);

        }
        pop3.Close(false);

    }
};
Imports Lesnikowski.Client
Imports Lesnikowski.Mail
Imports Lesnikowski.Mail.Headers
Imports Lesnikowski.Mail.Headers.Constants

Class Program
    Shared Sub Main()
        Dim pop3 As New Pop3
        pop3.User = "lesnikowski"               ' Set user name and password
        pop3.Password = "password"

        pop3.Connect("mail.host.com")           ' Connect to server and login
        pop3.Login()
        pop3.GetAccountStat()                   ' Get account statistics

        Dim builder As New SimpleMailMessageBuilder()
        For i As Integer = 1 To pop3.MessageCount
            Dim simpleMail As ISimpleMailMessage
            simpleMail = builder.CreateFromEml(pop3.GetMessage(i))

            ' Write out email's subject
            Console.WriteLine(simpleMail.Subject)
        Next
        pop3.Close(False)                       ' Close connection
    End Sub

End Class
Send an email
You have to create ISimpleMailMessage object. Use SimpleMailMessageBuilder class to do this.
Then connect to your SMTP server and send your message.
Typically SMTP server is working on port 25.
Use Smtp.Connect(string host) method to connect to the server.
using System;
using Lesnikowski.Client;
using Lesnikowski.Mail;
using Lesnikowski.Mail.Headers;
using Lesnikowski.Mail.Headers.Constants;

class Program
{
    static void Main(string[] args)
    {
        SimpleMailMessageBuilder builder = new SimpleMailMessageBuilder();

        // Set From and To fields
        builder.From.Add(new MailBox("alice@mail.com", "Alice"));
        builder.To.Add(new MailBox("bob@mail.com", "Bob"));

        builder.Subject = "Test";                   // Set subject
        builder.SetTextData("This is plain text message.");

        // Create new email message
        ISimpleMailMessage sm = builder.Create();

        // Send the message
        Smtp smtp = new Smtp();
        smtp.User = "lesnikowski";                  // Set username & password
        smtp.Password = "password";
        smtp.Connect("mail.host.com");              // Connect to the server
        smtp.Ehlo(HeloType.EhloHelo, "yourname");   // Say hello to the server
        smtp.Login();

        smtp.SendMessage(sm);                       // Send

        smtp.Close(false);                          // Close connection
    }
};
Imports Lesnikowski.Client
Imports Lesnikowski.Mail
Imports Lesnikowski.Mail.Headers
Imports Lesnikowski.Mail.Headers.Constants

Class Program
    Shared Sub Main()
        Dim builder As New SimpleMailMessageBuilder()
        
        builder.From.Add(New MailBox("alice@mail.com", "Alice"))
        builder.To.Add(New MailBox("bob@mail.com", "Bob"))
        builder.Subject = "Test"                     ' Set subject
        builder.SetTextData("This is plain text message.")

        ' Create new email message
        Dim sm As ISimpleMailMessage = builder.Create()

        ' Send the message
        Dim smtp As Smtp = New Smtp
        smtp.User = "lesnikowski"                   ' Set user name and password
        smtp.Password = "password"
        smtp.Connect("mail.host.com")               ' Connect to server and login
        smtp.Ehlo(HeloType.EhloHelo, "yourname")    ' Say hello to the server
        smtp.Login()

        smtp.SendMessage(sm)                        ' Send email message

        smtp.Close(False)                           ' Close connection
    End Sub
End Class