MailBee. NET Objects Tutorials

Upgrade path

General

Enable logging

VB

pop.EnableLogging = True
pop.LogFilePath = "C:\log.txt"
pop.ClearLog 

VB.NET

pop.Log.Enabled = True
pop.Log.Filename = "C:\log.txt"
pop.Log.Clear

Assign a license key

VB

Set pop = CreateObject("MailBee.POP3")
pop.LicenseKey = "put your license key here"

VB.NET

MailBee.Pop3Mail.Pop3.LicenseKey = "put your license key here"

Message

Add an attachment

VB

msg.AddAttachment "C:\archive.zip"

VB.NET

msg.Attachments.Add("C:\archive.zip") 

Add a custom header

VB

msg.AddHeader "Organization", "MyCompany"

VB.NET

msg.Headers.Add("Organization", "MyCompany", False)

Encode header text using international characters

VB

msg.EncodeHeaderText "From", msg.FromAddr, "windows-1251", 3

VB.NET

msg.EncodeAllHeaders(Encoding.GetEncoding("windows-1251"), HeaderEncodingOptions.Base64)

Prepare HTML-formatted messages for displaying them locally, also saving embedded objects of the message into default or user-specified temporary location

VB

msg.GetBodyWithEmbeddedObjects "C:\", "Temp"

VB.NET

msg.Parser.WorkingFolder = "C:\Temp\"
msg.GetHtmlAndSaveRelatedFiles()

Get the friendly name from the specified full e-mail address

VB

msg.GetFriendlyName Msg.FromAddr

VB.NET

msg.From.DisplayName

Get value of specified message header

VB

msg.GetHeader "X-Mailer"

VB.NET

msg.Headers("X-Mailer")

Get html version of specified message

VB

strPlain = msg.GetHtmlFromPlain(msg.BodyText)

VB.NET

msg.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml
msg.Parser.PlainToHtmlOptions = PlainToHtmlConvertOptions.UriToLink
strHtml = msg.BodyHtmlText

Get plain-text version of specified message

VB

strHtml = msg.GetPlainFromHtml(msg.BodyText)

VB.NET

msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain
msg.Parser.PlainToHtmlOptions = PlainToHtmlConvertOptions.UriToLink
strPlain = msg.BodyPlainText

Get the pure e-mail address

VB

msg.GetPureAddr msg.FromAddr

VB.NET

msg.From.Email

Load body of a message from the disk file that is in your HDD drive that is in your computer

VB

msg.ImportBodyText "C:\web_page.htm", True

VB.NET

msg.LoadBodyText("C:\web_page.htm", MessageBodyType.Html)

Load and parse an e-mail message from the disk file that is in your HDD drive that is in your computer

VB

msg.ImportFromFile "C:\message.eml"

VB.NET

msg.LoadMessage ("C:\message.eml")

Remove custom header from the message

VB

msg.RemoveHeader "X-Priority"

VB.NET

msg.Headers.Remove("X-Priority")

Save message content to the file

VB

msg.SaveMessage "C:\msg.eml"

VB.NET

msg.SaveMessage("C:\msg.eml")

Test whether specified email address is correct

VB

msg.ToAddr = "jdoe@domain.com"
msg.ValidateEmailAddress msg.ToAddr, 1 

VB.NET

mailer.To.AddFromString("joe@mysite.com")
mailer.TestSend(SendFailureThreshold.AllRecipientsFailed) 

Write content of the attachment (value of Content property) to the scecified folder

VB

attach.SaveFile "C:\Data Files"

VB.NET

attach.SaveToFolder("C:\Data Files\", true)

Get the binary content of the attachment as a string

VB

attach.Content

VB.NET

attach.GetData()

Remove the attachment with the specified index from the collection

VB

msg.Attachments.Remove 1

VB.NET

msg.Attachments.RemoveAt(1)

SMTP

Set SMTP server address and specify account credentials

VB

mailer.ServerName = "mail.domain.com"
mailer.UserName = "jdoe"
mailer.Password = "secret"

VB.NET

mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret")

Compose the message and extract the name of the SMTP server to be used to sent the message

VB

mailer.FromAddr = "bill@domain.com"
mailer.ToAddr = "jdoe@domain.com"
mailer.Subject = "Hello"
mailer.BodyText = "Simple message"
mailer.ServerName = objSMTP.GetRelayServerFromEmailAddress("jdoe@domain.com")
mailer.Send

VB.NET

MailBee.SmtpMail.Smtp.QuickSend("joe@me.com", "bill@you.com", "Hello", "Simple message")

Relay (forward) previously saved message to one or more recipients

VB

mailer.RelayMessage "C:\msg.eml", "jdoe@domain.com", "bill@domain.com, jane@domain.com"

VB.NET

mailer.RelayFromEmlFile("C:\msg.eml", "jdoe@domain.com", "bill@domain.com, jane@domain.com")

Destroy contained Message object and create new one

VB

mailer.ResetMessage

VB.NET

msg.Reset()

Send the message to SMTP server. In addition to standard sending functionality, allow sending messages from fake addresses

VB

mailer.SendEx "jdoe@domain.com", "bill@domain.com"

VB.NET

mailer.Send("jdoe@domain.com", "bill@domain.com")

Submit the message to the queue for delivery

VB

mailer.SendToQueue "C:\Inetpub\mailroot\Pickup"

VB.NET

mailer.SubmitToPickupFolder("C:\Inetpub\mailroot\Pickup")

Specify the authentication method

VB

mailer.ServerName = "mail.domain.com"
mailer.AuthMethod = 3
mailer.UserName = "jdoe"
mailer.Password = "secret"

VB.NET

mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret", AuthenticationMethods.SaslCramMD5)

Connect using secure SSL/TLS connections

VB

Set mailer = CreateObject("MailBee.SMTP")
Set SSL = CreateObject("MailBee.SSL")
Set mailer.SSL = SSL
mailer.PortNumber = 465
mailer.ServerName = "mail.domain.com"
mailer.UserName = "jdoe"
mailer.Password = "secret"
mailer.Connect

VB.NET

Dim mailer As New Smtp
Dim server As SmtpServer = New SmtpServer("mail.domain.com", "jdoe", "secret")
server.Port = 465
server.SslMode = SslStartupMode.OnConnect
mailer.SmtpServers.Add(server)

POP3

Connect and log into POP3 mail account

VB

pop.Connect "mailserver.com", 110, "jdoe", "secret"

VB.NET

pop.Connect("mail.domain.com", 110)
pop.Login("jdoe", "secret")

Mark specified message for deletion

VB

pop.DeleteMessage 1

VB.NET

pop.DeleteMessage(1)

Get the ordinal position of a message given its Unique-ID

VB

pop.GetMessageNumberFromUID(strUID)

VB.NET

pop.GetMessageIndexFromUid(strUID)

Get UID value for a message

VB

pop.GetMessageUID(1)

VB.NET

pop.GetMessageUidFromIndex(1)

Send "noop" command to POP3 server

VB

pop.Ping

VB.NET

pop.Noop()

Retrieve headers for all messages from the e-mail account

VB

Set msgs = pop.RetrieveHeaders

VB.NET

Dim msgs As MailMessageCollection
msgs = pop.DownloadMessageHeaders()

Retrieve headers for all messages from the e-mail account and partialy download some message body lines

VB

Set msgs = pop.RetrieveHeaders(10)

VB.NET

Dim msgs As MailMessageCollection
msgs = pop.DownloadMessageHeaders(1, -1, 10)

Retrieve all messages from the e-mail account

VB

Set msgs = Mailer.RetrieveMessages

VB.NET

Dim msgs As MailMessageCollection
msgs = pop.DownloadEntireMessages()

Retrieve a message from the e-mail account

VB

Set msg = pop.RetrieveSingleMessage(1)

VB.NET

Dim msg As MailMessage
msg = pop.DownloadEntireMessage(1)

Retrieve headers for a particular message from the e-mail account

VB

Set msg = pop.RetrieveSingleMessageHeaders(1)

VB.NET

Dim msg As MailMessage
msg = pop.DownloadMessageHeader(1)

Retrieve UIDs of all messages in currently opened mailbox

VB

Dim uids
uids = pop.Search

VB.NET

Dim uids As String() = pop.GetMessageUids()

Send user-defined text to POP3 server

VB

pop.SendCommand "rset" & vbCrLf

VB.NET

pop.ExecuteCustomCommand("rset" & vbCrLf, False)

Get total number of the messages in the currently opened mailbox

VB

pop.MessageCount

VB.NET

pop.InboxMessageCount

Establish connection with the POP3 server using various authentication types

VB

Mailer.ServerName = "mail.domain.com"
Mailer.UserName = "jdoe"
Mailer.Password = "secret"
Mailer.AuthMethod = 1
Mailer.Connect

VB.NET

pop.Connect("mail.domain.com")
pop.Login("jdoe", "secret", AuthenticationMethods.Apop)

Know whether POP3 object is performing long-run operation

VB

pop.Busy

VB.NET

pop.IsBusy

Get completion status of the last operation

VB

pop.ErrCode

VB.NET

pop.LastResult

Get size of particular message in e-mail account

VB

pop.Size 1

VB.NET

pop.GetMessageSize(1)

Get last reply of POP3 server

VB

pop.ServerResponse

VB.NET

pop.GetServerResponse()

Get total size of all messages in currently opened mailbox

VB

pop.TotalSize

VB.NET

pop.InboxSize

Connect using secure SSL/TLS connections

VB

Set pop = CreateObject("MailBee.POP3")
Set SSL = CreateObject("MailBee.SSL")
Set pop.SSL = SSL
pop.PortNumber = 995
pop.ServerName = "mail.domain.com"
pop.UserName = "jdoe"
pop.Pasword = "secret"
pop.Connect

VB.NET

Dim pop As New Pop3()
pop.SslProtocol = SecurityProtocol.Auto
pop.SslMode = SslStartupMode.OnConnect
pop.Connect("mail.domain.com", 995)
pop.Login("jdoe", "secret")

IMAP

Upload a message to the specified mailbox on the server

VB

imp.AppendMessage "Draft", msg.RawBody

VB.NET

imp.UploadMessage(msg, "Draft")

Connect to the IMAP4 server and log in specified user account

VB

imp.Connect "mail.domain.com", 143, "jdoe", "secret"

VB.NET

imp.Connect("mail.domain.com", 143)
imp.Login("jdoe", "secret")

Create a mailbox on the IMAP4 server

VB

imp.CreateMailbox "Archive"

VB.NET

imp.CreateFolder("Archive")

Delete existing mailbox from the IMAP4 server

VB

imp.DeleteMailbox "Archive"

VB.NET

imp.DeleteFolder("Archive") 

Select the specified folder for read-only access

VB

imp.ExamineMailbox "Inbox"

VB.NET

imp.ExamineFolder("Inbox")

Send "noop" command to IMAP4 server

VB

imp.Ping

VB.NET

imp.Noop()

Rename existing mailbox on the IMAP4 server

VB

imp.RenameMailbox "Archive", "Backup"

VB.NET

imp.RenameFolder("Archive", "Backup")

Retrieve one or more message envelopes from currently selected IMAP4 mailbox

VB

Set Envelopes = imp.RetrieveEnvelopes(1, 10, False)

VB.NET

Dim envs As EnvelopeCollection = imp.DownloadEnvelopes("1:10", false)

Retrieve Mailboxes collection which contains all mailboxes in the IMAP4 account

VB

Set Mailboxes = imp.RetrieveMailboxes

VB.NET

Dim folders As FolderCollection = imp.DownloadFolders()

Retrieve a message from currently selected IMAP4 mailbox

VB

Set msg = imp.RetrieveSingleMessage (1, False)

VB.NET

Dim msg As MailMessage = imp.DownloadEntireMessage(1, False)

Retrieve message headers from currently selected IMAP4 mailbox

VB

Set Message = Mailer.RetrieveSingleMessageHeaders(1, False)

VB.NET

Dim msgs As MailMessageCollection = imp.DownloadMessageHeaders("1:1", False)

Retrieve the total size (in bytes) of all messages in the currently selected IMAP4 mailbox

VB

imp.RetrieveTotalSize

VB.NET

imp.GetFolderSize()

Search the currently selected mailbox for messages which meet specified condition

VB

imp.Search(False, "RECENT")

VB.NET

imp.Search(False, "RECENT", System.Text.Encoding.Default.WebName)

Select specified mailbox on the IMAP4 server

VB

imp.SelectMailbox "Inbox"

VB.NET

imp.SelectFolder("Inbox")

Execute user-supplied command on the IMAP4 server

VB

imp.SendCommand "DONE"

VB.NET

imp.ExecuteCustomCommand("DONE", Nothing)

Set the flags for a message in the currently selected mailbox

VB

imp.SetFlagsForMessage 1, False, 2, 2

VB.NET

imp.SetMessageFlags(1, False, SystemMessageFlags.Deleted, MessageFlagAction.Remove)

Subscribe specified mailbox

VB

imp.Subscribe "Archive"

VB.NET

imp.SubscribeFolder("Archive")

Unsubscribe specified mailbox

VB

imp.Unsubscribe "Archive"

VB.NET

imp.UnsubscribeFolder("Archive")

Establish connection with the IMAP4 server using various authentication types

VB

imp.ServerName = "mail.domain.com"
imp.UserName = "jdoe"
imp.Password = "secret"
imp.AuthMethod = 1
imp.Connect

VB.NET

imp.Connect("mail.domain.com")
imp.Login("jdoe", "secret", AuthenticationMethods.Apop)

Know whether IMAP4 object is performing long-run operation

VB

imp.Busy

VB.NET

imp.IsBusy

Get completion status of the last operation

VB

imp.ErrCode

VB.NET

imp.LastResult

Get last reply of IMAP4 server

VB

imp.ServerResponse

VB.NET

imp.GetServerResponse()

Connect using secure SSL/TLS connections

VB

Set imp = CreateObject("MailBee.IMAP4")
Set SSL = CreateObject("MailBee.SSL")
Set imp.SSL = SSL
imp.PortNumber = 995
imp.ServerName = "mail.domain.com"
imp.UserName = "jdoe"
imp.Password = "secret"
imp.Connect

VB.NET

Dim imp As New Imap()
imp.SslProtocol = SecurityProtocol.Auto
imp.SslMode = SslStartupMode.OnConnect
imp.Connect("mail.domain.com", 995)
imp.Login("jdoe", "secret")