6a33647f by TossPig

修改参数类型

为了保持向后兼容,
1 parent e5134873
...@@ -157,7 +157,17 @@ func (e *Email) Bytes() ([]byte, error) { ...@@ -157,7 +157,17 @@ func (e *Email) Bytes() ([]byte, error) {
157 } 157 }
158 158
159 // Add attach file to the send mail 159 // Add attach file to the send mail
160 func (e *Email) AttachFile(filename string, id string) (a *Attachment, err error) { 160 func (e *Email) AttachFile(args ...string) (a *Attachment, err error) {
161 argsLength := len(args)
162 if argsLength < 1 || argsLength > 2 {
163 return
164 }
165 filename := args[0]
166 id := ""
167 if argsLength > 1 {
168 id = args[1]
169 }
170 id = args[1]
161 f, err := os.Open(filename) 171 f, err := os.Open(filename)
162 if err != nil { 172 if err != nil {
163 return 173 return
...@@ -169,7 +179,18 @@ func (e *Email) AttachFile(filename string, id string) (a *Attachment, err error ...@@ -169,7 +179,18 @@ func (e *Email) AttachFile(filename string, id string) (a *Attachment, err error
169 179
170 // Attach is used to attach content from an io.Reader to the email. 180 // Attach is used to attach content from an io.Reader to the email.
171 // Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type. 181 // Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type.
172 func (e *Email) Attach(r io.Reader, filename string, c string, id string) (a *Attachment, err error) { 182 func (e *Email) Attach(r io.Reader, filename string, ci ...string) (a *Attachment, err error) {
183 args := ci
184 argsLength := len(args)
185 if argsLength < 1 || argsLength > 2 {
186 return
187 }
188 c := args[0]
189 id := ""
190 if argsLength > 1 {
191 id = args[1]
192 }
193 id = args[1]
173 var buffer bytes.Buffer 194 var buffer bytes.Buffer
174 if _, err = io.Copy(&buffer, r); err != nil { 195 if _, err = io.Copy(&buffer, r); err != nil {
175 return 196 return
...@@ -189,7 +210,7 @@ func (e *Email) Attach(r io.Reader, filename string, c string, id string) (a *At ...@@ -189,7 +210,7 @@ func (e *Email) Attach(r io.Reader, filename string, c string, id string) (a *At
189 if id != "" { 210 if id != "" {
190 at.Header.Set("Content-Disposition", fmt.Sprintf("inline;\r\n filename=\"%s\"", filename)) 211 at.Header.Set("Content-Disposition", fmt.Sprintf("inline;\r\n filename=\"%s\"", filename))
191 at.Header.Set("Content-ID", fmt.Sprintf("<%s>", id)) 212 at.Header.Set("Content-ID", fmt.Sprintf("<%s>", id))
192 }else { 213 } else {
193 at.Header.Set("Content-Disposition", fmt.Sprintf("attachment;\r\n filename=\"%s\"", filename)) 214 at.Header.Set("Content-Disposition", fmt.Sprintf("attachment;\r\n filename=\"%s\"", filename))
194 } 215 }
195 at.Header.Set("Content-Transfer-Encoding", "base64") 216 at.Header.Set("Content-Transfer-Encoding", "base64")
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!