mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
Let's get started...
This commit is contained in:
parent
4af52c3414
commit
4dd9c1bf40
1 changed files with 58 additions and 0 deletions
58
client.go
Normal file
58
client.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package mail
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DefaultPort is the default connection port to the SMTP server
|
||||
const DefaultPort = 25
|
||||
|
||||
// DefaultTimeout is the default connection timeout
|
||||
const DefaultTimeout = time.Second * 30
|
||||
|
||||
// Client is the SMTP client struct
|
||||
type Client struct {
|
||||
h string // Hostname of the target SMTP server to connect to
|
||||
p int // Port of the SMTP server to connect to
|
||||
s bool // Use SSL/TLS or not
|
||||
ctx context.Context // The context for the connection handling
|
||||
}
|
||||
|
||||
// Option returns a function that can be used for grouping Client options
|
||||
type Option func(*Client)
|
||||
|
||||
// NewClient returns a new Session client object
|
||||
func NewClient(o ...Option) Client {
|
||||
c := Client{
|
||||
p: DefaultPort,
|
||||
}
|
||||
|
||||
// Override defaults with optionally provided Option functions
|
||||
for _, co := range o {
|
||||
if co == nil {
|
||||
continue
|
||||
}
|
||||
co(&c)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// WithHost overrides the default connection port
|
||||
func WithHost(h string) Option {
|
||||
return func(c *Client) {
|
||||
c.h = h
|
||||
}
|
||||
}
|
||||
|
||||
// WithPort overrides the default connection port
|
||||
func WithPort(p int) Option {
|
||||
return func(c *Client) {
|
||||
c.p = p
|
||||
}
|
||||
}
|
||||
|
||||
func (c Client) Dial() {
|
||||
|
||||
}
|
Loading…
Reference in a new issue