-
Notifications
You must be signed in to change notification settings - Fork 0
/
newman.go
70 lines (54 loc) · 2.19 KB
/
newman.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
58
59
60
61
62
63
64
65
66
67
68
69
70
package newman
import (
"context"
"github.com/theopenlane/newman/shared"
)
// EmailSender interface defines the method to send an email
type EmailSender interface {
// SendEmail sends an email with the given message
SendEmail(message *EmailMessage) error
// SendEmailWithContext sends an email with the given message and context
SendEmailWithContext(ctx context.Context, message *EmailMessage) error
}
// EmailMessage represents an email message
type EmailMessage = shared.EmailMessage
// Attachment represents an email attachment with its filename and content
type Attachment = shared.Attachment
// Tag is used to define custom metadata for message
type Tag = shared.Tag
// NewEmailMessage creates a new EmailMessage with the required fields
func NewEmailMessage(from string, to []string, subject string, body string) *EmailMessage {
return shared.NewEmailMessage(from, to, subject, body)
}
// NewEmailMessageWithOptions creates a new EmailMessage with the specified options.
func NewEmailMessageWithOptions(options ...MessageOption) *EmailMessage {
s := EmailMessage{}
for _, option := range options {
option(&s)
}
return &s
}
// NewAttachment creates a new Attachment instance with the specified filename and content
func NewAttachment(filename string, content []byte) *Attachment {
return shared.NewAttachment(filename, content)
}
// NewAttachmentFromFile creates a new Attachment instance from the specified file path
func NewAttachmentFromFile(filePath string) (*Attachment, error) {
return shared.NewAttachmentFromFile(filePath)
}
// BuildMimeMessage constructs the MIME message for the email, including text, HTML, and attachments
func BuildMimeMessage(message *EmailMessage) ([]byte, error) {
return shared.BuildMimeMessage(message)
}
// ValidateEmail validates and sanitizes an email address
func ValidateEmail(email string) string {
return shared.ValidateEmailAddress(email)
}
// ValidateEmailSlice validates and sanitizes a slice of email addresses
func ValidateEmailSlice(emails []string) []string {
return shared.ValidateEmailAddresses(emails)
}
// GetMimeType returns the MIME type based on the file extension
func GetMimeType(filename string) string {
return shared.GetMimeType(filename)
}