mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-23 06:10:48 +01:00
Compare commits
No commits in common. "de174da6fbb83a276df035ae5ce4644219a6262c" and "ae36ab8722f352e92f4cb4577bc791375a975c3a" have entirely different histories.
de174da6fb
...
ae36ab8722
2 changed files with 21 additions and 40 deletions
57
client.go
57
client.go
|
@ -253,6 +253,8 @@ func WithTimeout(timeout time.Duration) Option {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSSL tells the client to use a SSL/TLS connection
|
// WithSSL tells the client to use a SSL/TLS connection
|
||||||
|
//
|
||||||
|
// Deprecated: use WithSSLPort instead.
|
||||||
func WithSSL() Option {
|
func WithSSL() Option {
|
||||||
return func(c *Client) error {
|
return func(c *Client) error {
|
||||||
c.useSSL = true
|
c.useSSL = true
|
||||||
|
@ -260,16 +262,11 @@ func WithSSL() Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSSLPort tells the Client wether or not to use SSL and fallback.
|
// WithSSLPort tells the client to use a SSL/TLS connection.
|
||||||
// The correct port is automatically set.
|
// It automatically sets the port to 465.
|
||||||
//
|
//
|
||||||
// Port 465 is used when SSL set (true).
|
// When the SSL connection fails and fallback is set to true,
|
||||||
// Port 25 is used when SSL is unset (false).
|
|
||||||
// When the SSL connection fails and fb is set to true,
|
|
||||||
// the client will attempt to connect on port 25 using plaintext.
|
// the client will attempt to connect on port 25 using plaintext.
|
||||||
//
|
|
||||||
// Note: If a different port has already been set otherwise, the port-choosing
|
|
||||||
// and fallback automatism will be skipped.
|
|
||||||
func WithSSLPort(fallback bool) Option {
|
func WithSSLPort(fallback bool) Option {
|
||||||
return func(c *Client) error {
|
return func(c *Client) error {
|
||||||
c.SetSSLPort(true, fallback)
|
c.SetSSLPort(true, fallback)
|
||||||
|
@ -307,8 +304,7 @@ func WithHELO(helo string) Option {
|
||||||
|
|
||||||
// WithTLSPolicy tells the client to use the provided TLSPolicy
|
// WithTLSPolicy tells the client to use the provided TLSPolicy
|
||||||
//
|
//
|
||||||
// Note: To follow best-practices for SMTP TLS connections, it is recommended
|
// Deprecated: use WithTLSPortPolicy instead.
|
||||||
// to use WithTLSPortPolicy instead.
|
|
||||||
func WithTLSPolicy(policy TLSPolicy) Option {
|
func WithTLSPolicy(policy TLSPolicy) Option {
|
||||||
return func(c *Client) error {
|
return func(c *Client) error {
|
||||||
c.tlspolicy = policy
|
c.tlspolicy = policy
|
||||||
|
@ -323,9 +319,6 @@ func WithTLSPolicy(policy TLSPolicy) Option {
|
||||||
// If the connection fails with TLSOpportunistic,
|
// If the connection fails with TLSOpportunistic,
|
||||||
// a plaintext connection is attempted on port 25 as a fallback.
|
// a plaintext connection is attempted on port 25 as a fallback.
|
||||||
// NoTLS will allways use port 25.
|
// NoTLS will allways use port 25.
|
||||||
//
|
|
||||||
// Note: If a different port has already been set otherwise, the port-choosing
|
|
||||||
// and fallback automatism will be skipped.
|
|
||||||
func WithTLSPortPolicy(policy TLSPolicy) Option {
|
func WithTLSPortPolicy(policy TLSPolicy) Option {
|
||||||
return func(c *Client) error {
|
return func(c *Client) error {
|
||||||
c.SetTLSPortPolicy(policy)
|
c.SetTLSPortPolicy(policy)
|
||||||
|
@ -470,9 +463,6 @@ func (c *Client) ServerAddr() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTLSPolicy overrides the current TLSPolicy with the given TLSPolicy value
|
// SetTLSPolicy overrides the current TLSPolicy with the given TLSPolicy value
|
||||||
//
|
|
||||||
// Note: To follow best-practices for SMTP TLS connections, it is recommended
|
|
||||||
// to use SetTLSPortPolicy instead.
|
|
||||||
func (c *Client) SetTLSPolicy(policy TLSPolicy) {
|
func (c *Client) SetTLSPolicy(policy TLSPolicy) {
|
||||||
c.tlspolicy = policy
|
c.tlspolicy = policy
|
||||||
}
|
}
|
||||||
|
@ -484,19 +474,14 @@ func (c *Client) SetTLSPolicy(policy TLSPolicy) {
|
||||||
// If the connection fails with TLSOpportunistic, a plaintext connection is
|
// If the connection fails with TLSOpportunistic, a plaintext connection is
|
||||||
// attempted on port 25 as a fallback.
|
// attempted on port 25 as a fallback.
|
||||||
// NoTLS will allways use port 25.
|
// NoTLS will allways use port 25.
|
||||||
//
|
|
||||||
// Note: If a different port has already been set otherwise, the port-choosing
|
|
||||||
// and fallback automatism will be skipped.
|
|
||||||
func (c *Client) SetTLSPortPolicy(policy TLSPolicy) {
|
func (c *Client) SetTLSPortPolicy(policy TLSPolicy) {
|
||||||
if c.port == DefaultPort {
|
c.port = DefaultPortTLS
|
||||||
c.port = DefaultPortTLS
|
|
||||||
|
|
||||||
if policy == TLSOpportunistic {
|
if policy == TLSOpportunistic {
|
||||||
c.fallbackPort = DefaultPort
|
c.fallbackPort = DefaultPort
|
||||||
}
|
}
|
||||||
if policy == NoTLS {
|
if policy == NoTLS {
|
||||||
c.port = DefaultPort
|
c.port = DefaultPort
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.tlspolicy = policy
|
c.tlspolicy = policy
|
||||||
|
@ -514,19 +499,15 @@ func (c *Client) SetSSL(ssl bool) {
|
||||||
// Port 25 is used when SSL is unset (false).
|
// Port 25 is used when SSL is unset (false).
|
||||||
// When the SSL connection fails and fb is set to true,
|
// When the SSL connection fails and fb is set to true,
|
||||||
// the client will attempt to connect on port 25 using plaintext.
|
// the client will attempt to connect on port 25 using plaintext.
|
||||||
//
|
|
||||||
// Note: If a different port has already been set otherwise, the port-choosing
|
|
||||||
// and fallback automatism will be skipped.
|
|
||||||
func (c *Client) SetSSLPort(ssl bool, fallback bool) {
|
func (c *Client) SetSSLPort(ssl bool, fallback bool) {
|
||||||
if c.port == DefaultPort {
|
c.port = DefaultPort
|
||||||
if ssl {
|
if ssl {
|
||||||
c.port = DefaultPortSSL
|
c.port = DefaultPortSSL
|
||||||
}
|
}
|
||||||
|
|
||||||
c.fallbackPort = 0
|
c.fallbackPort = 0
|
||||||
if fallback {
|
if fallback {
|
||||||
c.fallbackPort = DefaultPort
|
c.fallbackPort = DefaultPort
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.useSSL = ssl
|
c.useSSL = ssl
|
||||||
|
|
|
@ -777,9 +777,9 @@ func TestClient_SetLogger(t *testing.T) {
|
||||||
if c.logger == nil {
|
if c.logger == nil {
|
||||||
t.Errorf("Expected Logger to be set but received nil")
|
t.Errorf("Expected Logger to be set but received nil")
|
||||||
}
|
}
|
||||||
c.logger.Debugf(log.Log{Direction: log.DirServerToClient, Format: "%s", Messages: []interface{}{"test"}})
|
c.logger.Debugf(log.Log{Direction: log.DirServerToClient, Format: "", Messages: []interface{}{"test"}})
|
||||||
c.SetLogger(nil)
|
c.SetLogger(nil)
|
||||||
c.logger.Debugf(log.Log{Direction: log.DirServerToClient, Format: "%s", Messages: []interface{}{"test"}})
|
c.logger.Debugf(log.Log{Direction: log.DirServerToClient, Format: "", Messages: []interface{}{"test"}})
|
||||||
}
|
}
|
||||||
|
|
||||||
var newClientServer = `220 hello world
|
var newClientServer = `220 hello world
|
||||||
|
|
Loading…
Reference in a new issue