-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new html templates for mail notifications * plain text notifications now include the link to finish the process via UI * include plain version when html body is defined in smtp emails, new notification flag to enable or disable link tracking (using filters in X-SMTPAPI header) * new generateVerificationCode method to generate a verification code and link for any kind of database code type, org invite verification code included * new api method to send mail notifications
- Loading branch information
1 parent
1aa9fbb
commit 2ff488e
Showing
23 changed files
with
3,464 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/vocdoni/saas-backend/internal" | ||
"github.com/vocdoni/saas-backend/notifications/mailtemplates" | ||
) | ||
|
||
// sendMail method sends a notification to the email provided. It requires the | ||
// email template and the data to fill it. It executes the mail template with | ||
// the data to get the notification and sends it with the recipient email | ||
// address provided. It returns an error if the mail service is available and | ||
// the notification could not be sent or the email address is invalid. If the | ||
// mail service is not available, it does nothing. | ||
func (a *API) sendMail(ctx context.Context, to string, mail mailtemplates.MailTemplate, data any) error { | ||
if a.mail != nil { | ||
ctx, cancel := context.WithTimeout(ctx, time.Second*10) | ||
defer cancel() | ||
// check if the email address is valid | ||
if !internal.ValidEmail(to) { | ||
return fmt.Errorf("invalid email address") | ||
} | ||
// execute the mail template to get the notification | ||
notification, err := mail.ExecTemplate(data) | ||
if err != nil { | ||
return err | ||
} | ||
// set the recipient email address | ||
notification.ToAddress = to | ||
// send the mail notification | ||
if err := a.mail.SendNotification(ctx, notification); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.