I am trying to programming an authentication system with golang.
After user successfully sign up, it will send an email confirmation to the user.
I am thinking to execute the send mail function in a goroutine. The code of send mail function looks like
func Send(email, link string) error {
// Connect to the remote SMTP server.
c, err := smtp.Dial("127.0.0.1:2525")
if err != nil {
return err
}
// Set the sender and recipient.
c.Mail("sender@example.org")
c.Rcpt(email)
// Send the email body.
wc, err := c.Data()
if err != nil {
return err
}
defer wc.Close()
buf := bytes.NewBufferString("Please confirm this email " + link)
if _, err = buf.WriteTo(wc); err != nil {
return err
}
return nil
}
If here an error is going to occur in the goroutine and response is already done(the user receive the response), how can I then handle the error?