github.com/blend/go-sdk@v1.20220411.3/email/message_option.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package email 9 10 // ApplyMessageOptions applies options to a message and returns 11 // the mutated copy. 12 func ApplyMessageOptions(m Message, options ...MessageOption) Message { 13 for _, option := range options { 14 option(&m) 15 } 16 return m 17 } 18 19 // MessageOption is a mutator for messages. 20 type MessageOption func(m *Message) 21 22 // OptFrom sets the from address for a message. 23 func OptFrom(from string) MessageOption { 24 return func(m *Message) { 25 m.From = from 26 } 27 } 28 29 // OptTo sets the to address for a message. 30 func OptTo(to ...string) MessageOption { 31 return func(m *Message) { 32 m.To = to 33 } 34 } 35 36 // OptCC sets the cc addresses for a message. 37 func OptCC(cc ...string) MessageOption { 38 return func(m *Message) { 39 m.CC = cc 40 } 41 } 42 43 // OptBCC sets the bcc addresses for a message. 44 func OptBCC(bcc ...string) MessageOption { 45 return func(m *Message) { 46 m.BCC = bcc 47 } 48 } 49 50 // OptSubject sets the subject for a message. 51 func OptSubject(subject string) MessageOption { 52 return func(m *Message) { 53 m.Subject = subject 54 } 55 } 56 57 // OptTextBody sets the text body for a message. 58 func OptTextBody(textBody string) MessageOption { 59 return func(m *Message) { 60 m.TextBody = textBody 61 } 62 } 63 64 // OptHTMLBody sets the html body for a message. 65 func OptHTMLBody(htmlBody string) MessageOption { 66 return func(m *Message) { 67 m.HTMLBody = htmlBody 68 } 69 }