mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
Calling it a day...
This commit is contained in:
parent
b3554a9578
commit
82bb87ea4f
2 changed files with 11 additions and 7 deletions
15
client.go
15
client.go
|
@ -50,9 +50,6 @@ type Option func(*Client)
|
|||
var (
|
||||
// ErrNoHostname should be used if a Client has no hostname set
|
||||
ErrNoHostname = errors.New("hostname for client cannot be empty")
|
||||
|
||||
// ErrNoSTARTTLS should be used if the target server does not support the STARTTLS protocol
|
||||
ErrNoSTARTTLS = errors.New("target host does not support STARTTLS")
|
||||
)
|
||||
|
||||
// NewClient returns a new Session client object
|
||||
|
@ -120,6 +117,11 @@ func (c *Client) TLSPolicy() string {
|
|||
return fmt.Sprintf("%s", c.tlspolicy)
|
||||
}
|
||||
|
||||
// ServerAddr returns the currently set combination of hostname and port
|
||||
func (c *Client) ServerAddr() string {
|
||||
return fmt.Sprintf("%s:%d", c.host, c.port)
|
||||
}
|
||||
|
||||
// SetTLSPolicy overrides the current TLSPolicy with the given TLSPolicy value
|
||||
func (c *Client) SetTLSPolicy(p TLSPolicy) {
|
||||
c.tlspolicy = p
|
||||
|
@ -161,10 +163,10 @@ func (c *Client) DialWithContext(uctx context.Context) error {
|
|||
var co net.Conn
|
||||
var err error
|
||||
if c.ssl {
|
||||
co, err = td.DialContext(ctx, "tcp", fmt.Sprintf("%s:%d", c.host, c.port))
|
||||
co, err = td.DialContext(ctx, "tcp", c.ServerAddr())
|
||||
}
|
||||
if !c.ssl {
|
||||
co, err = nd.DialContext(ctx, "tcp", fmt.Sprintf("%s:%d", c.host, c.port))
|
||||
co, err = nd.DialContext(ctx, "tcp", c.ServerAddr())
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -180,7 +182,8 @@ func (c *Client) DialWithContext(uctx context.Context) error {
|
|||
|
||||
if !c.ssl && c.tlspolicy != NoTLS {
|
||||
if ok, _ := c.sc.Extension("STARTTLS"); !ok {
|
||||
return ErrNoSTARTTLS
|
||||
return fmt.Errorf("STARTTLS mode set to: %q, but target host does not support STARTTLS",
|
||||
c.tlspolicy)
|
||||
}
|
||||
if err := c.sc.StartTLS(c.tlsconfig); err != nil {
|
||||
return err
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
c, err := mail.NewClient("manjaro-vm.fritz.box", mail.WithTimeout(time.Millisecond*500))
|
||||
th := os.Getenv("TEST_HOST")
|
||||
c, err := mail.NewClient(th, mail.WithTimeout(time.Millisecond*500))
|
||||
if err != nil {
|
||||
fmt.Printf("failed to create new client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
Loading…
Reference in a new issue