Upgrade path (MailBee.NET Objects Tutorials)

From AfterLogic Wiki

Jump to: navigation, search

Contents

General

Enable logging

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

Assign a license key

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

Message

Add an attachment

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

Add a custom header

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

Encode header text using international characters

msg.EncodeHeaderText "From", msg.FromAddr, "windows-1251", 3
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

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

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

msg.GetFriendlyName Msg.FromAddr
msg.From.DisplayName

Get value of specified message header

msg.GetHeader "X-Mailer"
msg.Headers("X-Mailer")

Get html version of specified message

strPlain = msg.GetHtmlFromPlain(msg.BodyText)
msg.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml
msg.Parser.PlainToHtmlOptions = PlainToHtmlConvertOptions.UriToLink
strHtml = msg.BodyHtmlText

Get plain-text version of specified message

strHtml = msg.GetPlainFromHtml(msg.BodyText)
msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain
msg.Parser.PlainToHtmlOptions = PlainToHtmlConvertOptions.UriToLink
strPlain = msg.BodyPlainText

Get the pure e-mail address

msg.GetPureAddr msg.FromAddr
msg.From.Email

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

msg.ImportBodyText "C:\web_page.htm", True
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

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

Remove custom header from the message

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

Save message content to the file

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

Test whether specified email address is correct

msg.ToAddr = "jdoe@domain.com"
msg.ValidateEmailAddress msg.ToAddr, 1
mailer.To.AddFromString("joe@mysite.com")
mailer.TestSend(SendFailureThreshold.AllRecipientsFailed)

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

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

Get the binary content of the attachment as a string

attach.Content
attach.GetData()

Remove the attachment with the specified index from the collection

msg.Attachments.Remove 1
msg.Attachments.RemoveAt(1)

SMTP

Set SMTP server address and specify account credentials

mailer.ServerName = "mail.domain.com"
mailer.UserName = "jdoe"
mailer.Password = "secret"
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

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
MailBee.SmtpMail.Smtp.QuickSend("joe@me.com", "bill@you.com", "Hello", "Simple message")

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

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

Destroy contained Message object and create new one

mailer.ResetMessage
msg.Reset()

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

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

Submit the message to the queue for delivery

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

Specify the authentication method

mailer.ServerName = "mail.domain.com"
mailer.AuthMethod = 3
mailer.UserName = "jdoe"
mailer.Password = "secret"
mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret", AuthenticationMethods.SaslCramMD5)

Connect using secure SSL/TLS connections

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
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

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

Mark specified message for deletion

pop.DeleteMessage 1
pop.DeleteMessage(1)

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

pop.GetMessageNumberFromUID(strUID)
pop.GetMessageIndexFromUid(strUID)

Get UID value for a message

pop.GetMessageUID(1)
pop.GetMessageUidFromIndex(1)

Send "noop" command to POP3 server

pop.Ping
pop.Noop()

Retrieve headers for all messages from the e-mail account

Set msgs = pop.RetrieveHeaders
Dim msgs As MailMessageCollection
msgs = pop.DownloadMessageHeaders()

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

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

Retrieve all messages from the e-mail account

Set msgs = Mailer.RetrieveMessages
Dim msgs As MailMessageCollection
msgs = pop.DownloadEntireMessages()

Retrieve a message from the e-mail account

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

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

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

Retrieve UIDs of all messages in currently opened mailbox

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

Send user-defined text to POP3 server

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

Get total number of the messages in the currently opened mailbox

pop.MessageCount
pop.InboxMessageCount

Establish connection with the POP3 server using various authentication types

Mailer.ServerName = "mail.domain.com"
Mailer.UserName = "jdoe"
Mailer.Password = "secret"
Mailer.AuthMethod = 1
Mailer.Connect
pop.Connect("mail.domain.com")
pop.Login("jdoe", "secret", AuthenticationMethods.Apop)

Know whether POP3 object is performing long-run operation

pop.Busy
pop.IsBusy

Get completion status of the last operation

pop.ErrCode
pop.LastResult

Get size of particular message in e-mail account

pop.Size 1
pop.GetMessageSize(1)

Get last reply of POP3 server

pop.ServerResponse
pop.GetServerResponse()

Get total size of all messages in currently opened mailbox

pop.TotalSize
pop.InboxSize

Connect using secure SSL/TLS connections

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
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

imp.AppendMessage "Draft", msg.RawBody
imp.UploadMessage(msg, "Draft")

Connect to the IMAP4 server and log in specified user account

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

Create a mailbox on the IMAP4 server

imp.CreateMailbox "Archive"
imp.CreateFolder("Archive")

Delete existing mailbox from the IMAP4 server

imp.DeleteMailbox "Archive"
imp.DeleteFolder("Archive")

Select the specified folder for read-only access

imp.ExamineMailbox "Inbox"
imp.ExamineFolder("Inbox")

Send "noop" command to IMAP4 server

imp.Ping
imp.Noop()

Rename existing mailbox on the IMAP4 server

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

Retrieve one or more message envelopes from currently selected IMAP4 mailbox

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

Retrieve Mailboxes collection which contains all mailboxes in the IMAP4 account

Set Mailboxes = imp.RetrieveMailboxes
Dim folders As FolderCollection = imp.DownloadFolders()

Retrieve a message from currently selected IMAP4 mailbox

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

Retrieve message headers from currently selected IMAP4 mailbox

Set Message = Mailer.RetrieveSingleMessageHeaders(1, False)
Dim msgs As MailMessageCollection = imp.DownloadMessageHeaders("1:1", False)

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

imp.RetrieveTotalSize
imp.GetFolderSize()

Search the currently selected mailbox for messages which meet specified condition

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

Select specified mailbox on the IMAP4 server

imp.SelectMailbox "Inbox"
imp.SelectFolder("Inbox")

Execute user-supplied command on the IMAP4 server

i

mp.SendCommand "DONE"
imp.ExecuteCustomCommand("DONE", Nothing)

Set the flags for a message in the currently selected mailbox

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

Subscribe specified mailbox

imp.Subscribe "Archive"
imp.SubscribeFolder("Archive")

Unsubscribe specified mailbox

imp.Unsubscribe "Archive"
imp.UnsubscribeFolder("Archive")

Establish connection with the IMAP4 server using various authentication types

imp.ServerName = "mail.domain.com"
imp.UserName = "jdoe"
imp.Password = "secret"
imp.AuthMethod = 1
imp.Connect
imp.Connect("mail.domain.com")
imp.Login("jdoe", "secret", AuthenticationMethods.Apop)

Know whether IMAP4 object is performing long-run operation

imp.Busy
imp.IsBusy

Get completion status of the last operation

imp.ErrCode
imp.LastResult

Get last reply of IMAP4 server

imp.ServerResponse
imp.GetServerResponse()

Connect using secure SSL/TLS connections

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
Dim imp As New Imap()
imp.SslProtocol = SecurityProtocol.Auto
imp.SslMode = SslStartupMode.OnConnect
imp.Connect("mail.domain.com", 995)
imp.Login("jdoe", "secret")