@@ -37,45 +37,59 @@ type message struct {
3737 attachments map [string ][]byte
3838}
3939
40+ // SetFrom sets the sender email.
4041func (m * message ) SetFrom (from string ) {
4142 m .from = from
4243}
44+
45+ // From returns the sender email.
4346func (m * message ) From () string {
4447 return m .from
4548}
4649
50+ // SetTo sets the receiver addresses.
4751func (m * message ) SetTo (to ... string ) {
4852 m .to = to
4953}
5054
55+ // To returns receivers.
5156func (m * message ) To () []string {
5257 return m .to
5358}
5459
60+ // SetCC sets the CC recipients.
5561func (m * message ) SetCC (cc ... string ) {
5662 m .cc = cc
5763}
5864
65+ // CC returns the CC recipients.
5966func (m * message ) CC () []string {
6067 return m .cc
6168}
6269
70+ // SetBCC sets the BCC recipients.
6371func (m * message ) SetBCC (bcc ... string ) {
6472 m .bcc = bcc
6573}
6674
75+ // BCC returns the BCC recipients.
6776func (m * message ) BCC () []string {
6877 return m .bcc
6978}
7079
80+ // SetSubject sets the subject.
7181func (m * message ) SetSubject (subject string ) {
7282 m .subject = subject
7383}
7484
85+ // Subject returns the Subject.
7586func (m * message ) Subject () string {
7687 return m .subject
7788}
7889
90+ // Attach attaches files
91+ //
92+ // Returns an error if one of files could not be read.
7993func (m * message ) Attach (files ... string ) error {
8094 for _ , file := range files {
8195 b , err := os .ReadFile (file )
@@ -89,36 +103,46 @@ func (m *message) Attach(files ...string) error {
89103 return nil
90104}
91105
106+ // Attachments returns the attachments.
92107func (m * message ) Attachments () map [string ][]byte {
93108 return m .attachments
94109}
95110
111+ // Body returns the body.
96112func (m * message ) Body () string {
97113 return m .body
98114}
99115
116+ // SetNormalPriority sets the email priority to 'normal'.
100117func (m * message ) SetNormalPriority () {
101118 m .priority = "normal"
102119}
103120
121+ // SetUrgentPriority sets the email priority to 'urgent'.
104122func (m * message ) SetUrgentPriority () {
105123 m .priority = "urgent"
106124}
107125
126+ // SetNonUrgentPriority sets the email priority to 'non-urgent'.
108127func (m * message ) SetNonUrgentPriority () {
109128 m .priority = "non-urgent"
110129}
111130
131+ // Priority returns the priority.
112132func (m * message ) Priority () string {
113133 return m .priority
114134}
115135
136+ // FromString creates a new message with content from given string.
116137func FromString (str string ) * message {
117138 m := new ()
118139 m .body = str
119140 return m
120141}
121142
143+ // FromTemplateString creates a new message with content from parsed template string.
144+ //
145+ // Returns an error if the template string could not be parsed.
122146func FromTemplateString (data any , tpl string ) (* message , error ) {
123147 buff := bytes.Buffer {}
124148 template , _ := template .New ("tinymail" ).Parse (tpl )
@@ -131,6 +155,9 @@ func FromTemplateString(data any, tpl string) (*message, error) {
131155 return m , nil
132156}
133157
158+ // FromTemplateFile creates a new message with content from parsed template file.
159+ //
160+ // Returns an error if the template file could not be parsed.
134161func FromTemplateFile (data any , filenames ... string ) (* message , error ) {
135162 buff := bytes.Buffer {}
136163 template , _ := template .ParseFiles (filenames ... )
@@ -143,6 +170,7 @@ func FromTemplateFile(data any, filenames ...string) (*message, error) {
143170 return m , nil
144171}
145172
173+ // new creates a new empty message.
146174func new () * message {
147175 return & message {
148176 from : "" ,
0 commit comments