ImapConnect Method (String, Int32) |
Connects to an IMAP4 server.
Namespace: MailBee.ImapMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public bool Connect(
string serverName,
int port
)
Public Function Connect (
serverName As String,
port As Integer
) As Boolean
Parameters
- serverName
- Type: SystemString
The name or IP address of the IMAP4 server. - port
- Type: SystemInt32
The port on which to communicate with the server. The standard IMAP4 port is 143. For TLS/SSL connections, dedicated port is 993
(however, TLS/SSL connections via regular port are possible too, see SslMode and StartTls topics).
Return Value
Type:
Booleantrue if a connection attempt succeeded; otherwise,
false.
Exceptions Remarks
By default, MailBee can autodetect if the mail server you're connecting to requires SSL connection (this works for
well-known mail services like gmail.com or live.com). Thus, this method can actually connect to the mail server on port 993 if you
specified "imap.gmail.com" as
serverName. To disable SSL mode and port autodetection,
set
AutodetectPortAndSslMode to
false.
Examples This sample connects to the IMAP4 server, logs in the account and selects "Inbox" folder, then downloads the last message entirely,
and displays filenames of all attachments.
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;
Imap imp = new Imap();
imp.Connect("mail.domain.com", 143);
imp.Login("jdoe", "secret");
imp.SelectFolder("Inbox");
MailMessage msg = imp.DownloadEntireMessage(imp.MessageCount, false);
foreach (Attachment attach in msg.Attachments)
{
Console.WriteLine(attach.Filename);
}
imp.Disconnect();
Imports MailBee
Imports MailBee.ImapMail
Imports MailBee.Mime
Dim imp As New Imap
imp.Connect("mail.domain.com", 143)
imp.Login("jdoe", "secret")
imp.SelectFolder("Inbox")
Dim msg As MailMessage = imp.DownloadEntireMessage(imp.MessageCount, False)
For Each attach As Attachment In msg.Attachments
Console.WriteLine(attach.Filename)
Next
imp.Disconnect()
See Also