{"action":"created","issue":{"url":"https://api.github.com/repos/go-gomail/gomail/issues/99","repository_url":"https://api.github.com/repos/go-gomail/gomail","labels_url":"https://api.github.com/repos/go-gomail/gomail/issues/99/labels{/name}","comments_url":"https://api.github.com/repos/go-gomail/gomail/issues/99/comments","events_url":"https://api.github.com/repos/go-gomail/gomail/issues/99/events","html_url":"https://github.com/go-gomail/gomail/issues/99","id":257010355,"number":99,"title":"m.Attach issue with more than one files","user":{"login":"gnsx","id":3590121,"avatar_url":"https://avatars2.githubusercontent.com/u/3590121?v=4","gravatar_id":"","url":"https://api.github.com/users/gnsx","html_url":"https://github.com/gnsx","followers_url":"https://api.github.com/users/gnsx/followers","following_url":"https://api.github.com/users/gnsx/following{/other_user}","gists_url":"https://api.github.com/users/gnsx/gists{/gist_id}","starred_url":"https://api.github.com/users/gnsx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnsx/subscriptions","organizations_url":"https://api.github.com/users/gnsx/orgs","repos_url":"https://api.github.com/users/gnsx/repos","events_url":"https://api.github.com/users/gnsx/events{/privacy}","received_events_url":"https://api.github.com/users/gnsx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-12T11:30:59Z","updated_at":"2017-10-31T01:19:33Z","closed_at":null,"author_association":"NONE","body":"I'm trying to send attachments by directly reading from the file buffer instead of physical files on the disk.\r\n\r\nAttachment Struct\r\n```\r\ntype FileAttachment struct {\r\n\tFilename    string\r\n\tFileContent []byte\r\n}\r\n```\r\nAfter attaching 3 files, tried doing the following\r\n\r\n```\r\nfor i := range fileAttachment {\r\n\t\t\tm.Attach(fileAttachment[i].Filename, gomail.SetCopyFunc(func(w io.Writer) error {\r\n\t\t\t\t_, err := w.Write(fileAttachment[i].FileContent)\r\n\t\t\t\treturn err\r\n\t\t\t}))\r\n\t\t}\r\n```\r\n\r\nThe files get sent successfully but, all the files become of the same filesize of the last file that was attached. Eg: File A 1kB, File B 2kB, FIle C 3kB. ALl the files become 3kB.\r\n\r\nHowever if the files are manually attached like shown below, they get sent just fine with the correct content being reproduced on the email \r\n\r\n```\r\nm.Attach(fileAttachment[0].Filename, gomail.SetCopyFunc(func(w io.Writer) error {\r\n      _ , err := w.Write(fileAttachment[0].FileContent)\r\n      return err\r\n}))\r\nm.Attach(fileAttachment[1].Filename, gomail.SetCopyFunc(func(w io.Writer) error {\r\n      _ , err := w.Write(fileAttachment[1].FileContent)\r\n      return err\r\n}))\r\nm.Attach(fileAttachment[2].Filename, gomail.SetCopyFunc(func(w io.Writer) error {\r\n      _ , err := w.Write(fileAttachment[2].FileContent)\r\n      return err\r\n}))\r\n```"},"comment":{"url":"https://api.github.com/repos/go-gomail/gomail/issues/comments/340631490","html_url":"https://github.com/go-gomail/gomail/issues/99#issuecomment-340631490","issue_url":"https://api.github.com/repos/go-gomail/gomail/issues/99","id":340631490,"user":{"login":"middelink","id":10226229,"avatar_url":"https://avatars0.githubusercontent.com/u/10226229?v=4","gravatar_id":"","url":"https://api.github.com/users/middelink","html_url":"https://github.com/middelink","followers_url":"https://api.github.com/users/middelink/followers","following_url":"https://api.github.com/users/middelink/following{/other_user}","gists_url":"https://api.github.com/users/middelink/gists{/gist_id}","starred_url":"https://api.github.com/users/middelink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/middelink/subscriptions","organizations_url":"https://api.github.com/users/middelink/orgs","repos_url":"https://api.github.com/users/middelink/repos","events_url":"https://api.github.com/users/middelink/events{/privacy}","received_events_url":"https://api.github.com/users/middelink/received_events","type":"User","site_admin":false},"created_at":"2017-10-31T01:19:33Z","updated_at":"2017-10-31T01:19:33Z","author_association":"NONE","body":"Your anonymous function in SetCopyFunc does not bind `i`, so by the time the function is called (during message assembly; so way later) all their `i` have 2 in them.\r\n\r\nInstead use a closure, which binds the required `i`. Like so https://play.golang.org/p/CZgr8aq9KE"}}
{"actor":{"display_login":"middelink"}}