Adding godotenv library to use our .env file for the smtp configuration. Updating main.go adding our logger first, load our .env file, retrieve values to initialize the mail application's struct. Updating registerUserHandler sending the user_welcome.tmpl email.
Some checks failed
Deploy Greenlight API / deploy (push) Failing after 15m11s

This commit is contained in:
Maxime Delporte
2025-11-30 17:22:32 +01:00
parent 68e606976f
commit 8954318e40
4 changed files with 47 additions and 3 deletions

View File

@@ -59,6 +59,13 @@ func (app *application) registerUserHandler(w http.ResponseWriter, r *http.Reque
return
}
// Call the Send() method on our Mail, passing in the user's email address, name of the template file, and the User struct containing the new user's data.
err = app.mailer.Send(user.Email, "user_welcome.tmpl", user)
if err != nil {
app.serverErrorResponse(w, r, err)
return
}
// Write a JSON response containing the user data along with a 201 Created status code
err = app.writeJSON(w, http.StatusCreated, envelope{"user": user}, nil)
if err != nil {