public SmtpServerConnectionDefinition DeepCloneWithSecureConnectionMethod(SecureConnectionMethod secureConnectionMethod) { var result = new SmtpServerConnectionDefinition( this.Host?.DeepClone(), this.Port.DeepClone(), secureConnectionMethod, this.Username?.DeepClone(), this.ClearTextPassword?.DeepClone()); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="SmtpServerConnectionDefinition"/> class. /// </summary> /// <param name="host">The host to connect to.</param> /// <param name="port">The port to connect to.</param> /// <param name="secureConnectionMethod">The method by which the connection is secured.</param> /// <param name="username">The username to use for authentication.</param> /// <param name="clearTextPassword">The clear text password to use for authentication.</param> public SmtpServerConnectionDefinition( string host, int port, SecureConnectionMethod secureConnectionMethod, string username, string clearTextPassword) { new { host }.AsArg().Must().NotBeNullNorWhiteSpace(); new { port }.AsArg().Must().BeGreaterThanOrEqualTo(1).And().BeLessThanOrEqualTo(65535); new { secureConnectionMethod }.AsArg().Must().NotBeEqualTo(SecureConnectionMethod.Unknown); new { username }.AsArg().Must().NotBeNullNorWhiteSpace(); new { clearTextPassword }.AsArg().Must().NotBeNullNorWhiteSpace(); this.Host = host; this.Port = port; this.SecureConnectionMethod = secureConnectionMethod; this.Username = username; this.ClearTextPassword = clearTextPassword; }
private static SecureSocketOptions GetSecureSocketOptions( SecureConnectionMethod secureConnectionMethod) { SecureSocketOptions result; switch (secureConnectionMethod) { case SecureConnectionMethod.UseTlsOnConnect: result = SecureSocketOptions.SslOnConnect; break; case SecureConnectionMethod.StartTls: result = SecureSocketOptions.StartTls; break; default: throw new NotSupportedException(Invariant($"This {nameof(SecureConnectionMethod)} is not supported: {secureConnectionMethod}.")); } return(result); }