-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (50 loc) · 1.87 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"os"
"github.com/rs/zerolog/log"
"github.com/jenswbe/smtp-cli/send"
)
var Version = "unknown"
func main() {
// Parse flags
var (
printVersion = flag.Bool("version", false, "Print version and exit")
host = flag.String("host", "localhost", "Hostname of the server")
port = flag.Uint("port", 465, "Port of the server")
username = flag.String("username", "", "Username for authentication")
password = flag.String("password", "", "Password for authentication")
fromName = flag.String("from-name", "", "Name of the sender")
fromAddress = flag.String("from-address", "", "Address of the sender. Defaults to username.")
toName = flag.String("to-name", "", "Name of the receiver")
toAddress = flag.String("to-address", "", "Address of the receiver")
subject = flag.String("subject", "", "Subject of the email")
security = flag.String("security", "FORCE_TLS", "Supported options: FORCE_TLS (= implicit TLS), STARTTLS")
allowInsecureTLS = flag.Bool("allow-insecure-tls", false, "Skip TLS certificate verification. Should only be used for testing!")
)
flag.Parse()
if *printVersion {
fmt.Println(Version) //nolint
return
}
// Send email
err := send.SendEmail(send.EmailConfig{
Host: *host,
Port: *port,
Username: *username,
Password: *password,
FromName: *fromName,
FromAddress: *fromAddress,
ToName: *toName,
ToAddress: *toAddress,
Subject: *subject,
BodyReader: os.Stdin,
Security: *security,
AllowInsecureTLS: *allowInsecureTLS,
})
if err != nil {
log.Fatal().Err(err).Msg("Failed to send email")
}
log.Info().Str("subject", *subject).Str("to_name", *toName).Str("to_address", *toAddress).Msg("Email successfully sent")
}