Occurs when MailBee needs a new socket object for establishing a connection with the IMAP4 server.
Namespace: MailBee.ImapMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax Remarks This event is raised just before MailBee will start making the connection (i.e. before
SocketConnected event).
This lets you specify your own socket object in case if you need some special socket settings. For instance, configure SSL settings for new sockets in UWP apps.
If you need this, set
NewSocket property to the socket object needed in your event handler.
Note |
---|
It's possible that this event will fire multiple times in case if the host has multple endpoints assigned. For instance, if the first endpoint was IPv6,
the connection could not be made but second endpoint (IPv4) would succeed. On each call of this event handler, your code must supply a new, fresh socket object (otherwise MailBee
will create its own). By default, however, MailBee tries IPv4 addresses first (see PreferIPv4Hosts) so this situation is unlikely to happen. |
Examples This code snippet shows how to ignore some SSL certificate errors when making SSL/TLS connections in a UWP app (useful if you connect to local hosts with self-signed certificates, etc).
static void Imp_SocketCreating(object sender, SocketCreatingEventArgs e)
{
e.NewSocket = new StreamSocket();
e.NewSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
e.NewSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
e.NewSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
}
...
Imap imp = new Imap();
imp.SocketCreating += new SocketCreatingEventHandler(Imp_SocketCreating);
await imp.ConnectAsync("imap.gmail.com", 993);
...
Sub Imp_SocketCreating(sender As Object, e As SocketCreatingEventArgs)
e.NewSocket = New StreamSocket()
e.NewSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName)
e.NewSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted)
e.NewSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired)
End Sub
...
Dim imp As Imap = New Imap()
AddHandler imp.SocketCreating, AddressOf Imp_SocketCreating
Await imp.ConnectAsync("imap.gmail.com", 993)
...
See Also