I apologize in advance if this is an 'obvious' question.
I am especially new to MailKit and new to C# in general.
To open a new IMAP connection, I am using the following code, taken straight from MailKit's introductory GitHub notes:
using (var client = new ImapClient())
{
client.Connect("imap.gmail.com", 993, true);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH");
client.Authenticate("emailAddress", "pass");
// The Inbox folder is always available on all IMAP servers...
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly);
}
I have a class that contains functions related to e-mail management.
I would like the ImapClient 'client' and ImapClient.Inbox 'inbox' instances to persist throughout my class so that each function can access the inbox without having to run the connection procedure above. How can I make these instances persist throughout my class?
To say this in another way, I would like to run the connection procedure once (preferably when declaring the instance of my class), then have all subsequent methods access the inbox through this initial connection procedure.
Thanks in advance.