Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Multiple attachments are overwritten with last attachment using Attach() #53

Closed
andysnowden opened this issue Mar 27, 2019 · 2 comments
Closed

Comments

@andysnowden
Copy link

Per original issue go-gomail#126 this is still happening. The issue however does not occur when using the AttachReader() variant

@steviesama
Copy link

steviesama commented May 21, 2019

@andysnowden I haven't sent multiple with this repo yet...but I have code in production using the old repo and Attach() was resulting in all the appropriate attachments. Is there a way to reproduce this?

I have updated the code to use this active repo though...so if there's gonna be a problem...I'll see it soon.

@BarakatX2
Copy link

@andysnowden I don't think the problem in that issue is a bug in the library. It is likely the use of the loop variable in a closure. The loop variable f gets captured in the closures. When the closures are called after the loop completes, they all use the same variable which contains the last loop value. SetCopyFunc takes the given closure and stores it in a file object, so by the time the closure is called later it is using the captured loop variable that contains the last loop value. Here is an example showing how the loop variable returns the last loop value while the copied version of the loop variable is the expected value (you can also copy the loop variable by wrapping the loop code with a closure to avoid having a different variable name): https://play.golang.org/p/b6u5Yuce0_J

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants