go-gomail / gomail

The best way to send emails in Go.
MIT License
4.33k stars 573 forks source link

Attachment API #4

Closed kron4eg closed 9 years ago

kron4eg commented 9 years ago

I have the feeling that those signatures should have io.Reader instead of *File

func OpenFile(filename string) (*File, error)
func (msg *Message) Attach(f ...*File)
func (msg *Message) Embed(image ...*File)

And using ioutil.ReadFile (inside CreateFile()) will dump whole file contents right into memory...Which is not very good for performance and in general.

alexcesaro commented 9 years ago

Until very recently Gomail used smtp.SendMail from the standard library to send emails and that function takes msg []byte as an argument. So the whole email needed to be in memory anyway.

Now that Gomail use a custom function to send emails, the email could be streamed to the SMTP server. So it is true that the content field of File could now be an io.Reader instead of []byte.

However doing that change will break backward compatibility because the signatures of File, OpenFile, CreateFile and SetSendMail will have to be updated.

Since this is not a big issue (email attachments are supposed to be relatively small) I will wait for other breaking changes before fixing this issue and bumping the version number.