go-gomail / gomail

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

If file for Embed() is missing, the error is returned but email is still sent #65

Open wkhere opened 7 years ago

wkhere commented 7 years ago

Hi!

This library is very helpful. However, I encountered an inconsistent behaviour which I believe is a bug.

When a file given as an argument to Message.Embed(...) is missing on the filesystem, there's no error returned (this method returns nothing). Later, when calling Send(sender, message), error is returned, but the email is sent (without embedded data of course).

This is confusing - I'd rather expect that when there's an error, an email would not be sent. When it works this way, I cannot really differentiate between such error and other error stopping message from being sent.

leventogut commented 7 years ago

Same problem exists on attachments as well

wkhere commented 7 years ago

yep @leventogut I was suspecting it may affect regular attachments as well. Any idea of a fix guys? haven't dived into the source, yet

leventogut commented 7 years ago

haven't checked the code either , I am handling this on upper level not to cause any problems.

have been quite busy so couldn't spend time on it .

wkhere commented 7 years ago

Any thoughs on that @alexcesaro ?

In theory there's this CopyFunc registered for both attachments and embeds and this function should return an error which then should be handled properly before sending an email. In addFiles/writeBody methods I can see that some field of messageWriter struct is updated with an error. What next? How it is used then?

Gamma169 commented 7 years ago

I implemented a fix for this issue. Check my pull request. #97

wkhere commented 6 years ago

Looks cool. Will integrate it soon with my client code.

@alexcesaro ?