The IMAP4.LoadFromConfig() method Loads various settings from the configuration file (typically the web.config or app.config) and converts the various values to their respective properties. These settings must be specially named. They are, as follows:
| AppSetting Name | Sets the following Properties |
| IMAP4.AuthenticationType | Sets IMAP4.AuthenticationType |
| IMAP4.logger.Enabled | Sets Logger.Enabled |
| IMAP4.logger.InMemory | Sets Logger.InMemory |
| IMAP4.logger.Overwrite | Sets Logger.Overwrite |
| IMAP4.logger.Path | Sets Logger.Path |
| IMAP4.logger.SendToASPNETTrace | Sets Logger.SendToASPNETTrace |
| IMAP4.Password | Sets IMAP4.Password |
| IMAP4.Port | Sets IMAP4.Port |
| IMAP4.Server | Sets IMAP4.Server |
| IMAP4.SocketBufferSize | Sets IMAP4.SocketBufferSize |
| IMAP4.Timeout | Sets IMAP4.TimeOut |
| IMAP4.Username | Sets IMAP4.Username |
| IMAP4.IMAP4rev1 | Sets IMAP4.IMAP4rev1 |
The following example demonstrates creating an IMAP4 object, based
upon values found in the web.config file.
[configuration file (web.config)]
<appSettings> <add key="IMAP4.Server" value="127.0.0.1"/> <add key="IMAP4.Username" value="dave@blah.com" /> <add key="IMAP4.Password" value="test"/> <add key="IMAP4.Logger.Enabled" value="true"/> <add key="IMAP4.Logger.Path" value="c:\imap.log"/> <add key="IMAP4.Logger.Overwrite" value="true"/> <add key="IMAP4.Logger.InMemory" value="true"/> <add key="sample1_IMAP4.Logger.Path" value="c:\sampleimap.log"/> </appSettings>
[C#]
IMAP4 imap = new IMAP4(); imap.LoadFromConfig(); imap.Login(); //list all of the folders MailFolderCollection mfc = imap.FolderList(); Console.WriteLine( mfc.ToString() ); //write out the log, the username and password will be masked Console.WriteLine( imap.Logger.ToString() ); imap.Disconnect(); Console.WriteLine( "Done" ); Console.ReadLine();
[VB.NET]
Dim imap As New IMAP4() imap.LoadFromConfig() imap.Login() 'list all of the folders Dim mfc As MailFolderCollection = imap.FolderList() Console.WriteLine(mfc.ToString()) 'write out the log, the username and password will be masked Console.WriteLine(imap.Logger.ToString()) imap.Disconnect() Console.WriteLine("Done") Console.ReadLine()