Skip to content

Commit

Permalink
Allow developers to specify a local IPEndPoint to use for connecting …
Browse files Browse the repository at this point in the history
…to remote servers

Fixes issue #247
  • Loading branch information
jstedfast committed Sep 20, 2015
1 parent ce8a503 commit da1e52c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MailKit/IMailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public interface IMailService : IDisposable
/// </remarks>
/// <value>The server certificate validation callback function.</value>
RemoteCertificateValidationCallback ServerCertificateValidationCallback { get; set; }

/// <summary>
/// Get or set the local IP end point to use when connecting to the remote host.
/// </summary>
/// <remarks>
/// Gets or sets the local IP end point to use when connecting to the remote host.
/// </remarks>
/// <value>The local IP end point or <c>null</c> to use the default end point.</value>
IPEndPoint LocalEndPoint { get; set; }
#endif

/// <summary>
Expand Down
11 changes: 11 additions & 0 deletions MailKit/MailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ public X509CertificateCollection ClientCertificates {
public RemoteCertificateValidationCallback ServerCertificateValidationCallback {
get; set;
}

/// <summary>
/// Get or set the local IP end point to use when connecting to the remote host.
/// </summary>
/// <remarks>
/// Gets or sets the local IP end point to use when connecting to the remote host.
/// </remarks>
/// <value>The local IP end point or <c>null</c> to use the default end point.</value>
public IPEndPoint LocalEndPoint {
get; set;
}
#endif

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions MailKit/Net/Imap/ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,10 @@ static void ComputeDefaultValues (string host, ref int port, ref SecureSocketOpt

try {
cancellationToken.ThrowIfCancellationRequested ();

if (LocalEndPoint != null)
socket.Bind (LocalEndPoint);

socket.Connect (ipAddresses[i], port);
break;
} catch (OperationCanceledException) {
Expand Down
4 changes: 4 additions & 0 deletions MailKit/Net/Pop3/Pop3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,10 @@ static void ComputeDefaultValues (string host, ref int port, ref SecureSocketOpt

try {
cancellationToken.ThrowIfCancellationRequested ();

if (LocalEndPoint != null)
socket.Bind (LocalEndPoint);

socket.Connect (ipAddresses[i], port);
break;
} catch (OperationCanceledException) {
Expand Down
4 changes: 4 additions & 0 deletions MailKit/Net/Smtp/SmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@ static void ComputeDefaultValues (string host, ref int port, ref SecureSocketOpt

try {
cancellationToken.ThrowIfCancellationRequested ();

if (LocalEndPoint != null)
socket.Bind (LocalEndPoint);

socket.Connect (ipAddresses[i], port);
break;
} catch (OperationCanceledException) {
Expand Down

0 comments on commit da1e52c

Please sign in to comment.