IMAP
IMAP watcher is able to watch a single inbox and give a callback any time a new message is available to process.
There's a rich SDK that enables the IMAP client to respond to messages, attach images or HTML, get the body body, create reply messages, etc.
Authentication
There are two basic ways to authenticate with your IMAP server:
User/Pass
This is the "direct" method. If the server supports it, you can supply a username and password.
PerigeeApplication.ApplicationNoInit("EmailWatcher", (c) => {
c.AddIMAPWatcher("MailWatch",
"[email protected]", "MailBot", "password",
"hostImap", 993,
"smtphost", 587,
(ct, l, mail) => {
//Mail handler here!
});
});SASL
Simple Authentication Security Layer: This is for the authentication methods that require OAUTH2 or other methods.
An example of the google SASL callback:
The SDK
All of the SDK references below are available when a callback occurs for new mail messages to be processed.
Addresses
To get the various addresses:
Labels and Flags
Replying
The BodyBuilder callback is how you configure the outgoing message. You can see an example here of adding an image with CIDs.
The Reply method automatically configures the method reply parameters including the correct message headers, subject, response addresses, and if includeReplyText is true, it will also quote the original message back as any normal client would do.
Is ?
To see if the message is <FLAG>:
Delete Mail
To delete a message, issue the delete command.
The parameter is for expunging the message from the server as well as issuing the deleted flag.
Attachments
You can get a list of attachment parts, and iterate over them to get the actual content, mime type, name, etc.
Querying
To query the inbox:
Sent Box
If you need to access the sent box, we provide an easy way to retrieve and open the sent mailbox.
IMAP only allows a single mailbox to be open at once. Don't forget to call:
mail.OpenInbox();.
This verifies and prevents future issues with any subsequent calls to the mail client.
Input Text
Sometimes you just need whatever the person said, excluding their signature and reply content. This method takes several passes at retrieving just the top level user input and skipping the rest:
Low Level Access
There are a bunch of prebuilt methods to help with a mail client. If you want to do something specific, you can get the client and folder access as so, and use any of the available methods from MailKit:
Best practice watching
We highly recommend:
Putting a stop gap on the mail receive handler, something like
IsAnswered, as a way of preventing unwanted reprocessing of messages.Catching the exception and attempting to mark it answered and label it error if the client supports labelling.
Last updated

