Expanded mail client for easier email operations.
This commit is contained in:
parent
3f053711ba
commit
e8d73421aa
5 changed files with 160 additions and 59 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mikestefanello/pagoda/context"
|
||||
"github.com/mikestefanello/pagoda/controller"
|
||||
|
||||
|
|
@ -47,7 +49,14 @@ func (c *Contact) Post(ctx echo.Context) error {
|
|||
}
|
||||
|
||||
if !form.Submission.HasErrors() {
|
||||
if err := c.Container.Mail.Send(ctx, form.Email, "Hello!"); err != nil {
|
||||
err := c.Container.Mail.
|
||||
Compose().
|
||||
To(form.Email).
|
||||
Subject("Contact form submitted").
|
||||
Body(fmt.Sprintf("The message is: %s", form.Message)).
|
||||
Send(ctx)
|
||||
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "unable to send email")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,10 +84,14 @@ func (c *ForgotPassword) Post(ctx echo.Context) error {
|
|||
ctx.Logger().Infof("generated password reset token for user %d", u.ID)
|
||||
|
||||
// Email the user
|
||||
err = c.Container.Mail.Send(ctx, u.Email, fmt.Sprintf(
|
||||
"Go here to reset your password: %s",
|
||||
ctx.Echo().Reverse("reset_password", u.ID, token),
|
||||
))
|
||||
url := ctx.Echo().Reverse("reset_password", u.ID, token)
|
||||
err = c.Container.Mail.
|
||||
Compose().
|
||||
To(u.Email).
|
||||
Subject("Reset your password").
|
||||
Body(fmt.Sprintf("Go here to reset your password: %s", url)).
|
||||
Send(ctx)
|
||||
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "error sending password reset email")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,12 +105,16 @@ func (c *Register) sendVerificationEmail(ctx echo.Context, usr *ent.User) {
|
|||
}
|
||||
|
||||
// Send the email
|
||||
err = c.Container.Mail.Send(ctx, usr.Email, fmt.Sprintf(
|
||||
"Confirm your email address: %s",
|
||||
ctx.Echo().Reverse("verify_email", token),
|
||||
))
|
||||
url := ctx.Echo().Reverse("verify_email", token)
|
||||
err = c.Container.Mail.
|
||||
Compose().
|
||||
To(usr.Email).
|
||||
Subject("Confirm your email address").
|
||||
Body(fmt.Sprintf("Click here to confirm your email address: %s", url)).
|
||||
Send(ctx)
|
||||
|
||||
if err != nil {
|
||||
ctx.Logger().Errorf("unable to send email verification token: %v", err)
|
||||
ctx.Logger().Errorf("unable to send email verification link: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue