Sending mails using Foundation templates

This commit is contained in:
2024-07-17 22:34:03 +02:00
parent d40233b4ba
commit b1d3095c89
5 changed files with 1582 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package handlers
import (
"encoding/json"
"fmt"
"go-udemy-web-1/internal/config"
"go-udemy-web-1/internal/driver"
"go-udemy-web-1/internal/forms"
@ -172,6 +173,42 @@ func (m *Repository) PostMakeReservation(w http.ResponseWriter, r *http.Request)
return
}
// send notif to guest
htmlMessage := fmt.Sprintf(`
<strong>Reservation Confirmation</strong><br>
Dear %s: <br>
This is to confirm your reservation from %s to %s.
`, reservation.FirstName, reservation.StartDate.Format("2006-01-02"),
reservation.EndDate.Format("2006-01-02"))
msg := models.MailData{
To: reservation.Email,
From: "me@here.com",
Subject: "Reservation Confirmation",
Content: htmlMessage,
Template: "drip.html",
}
m.App.MailChan <- msg
// send notif to property owner
htmlMessage = fmt.Sprintf(`
<strong>Reservation Notification</strong><br>
A reservation has been made for %s from %s to %s.
`, reservation.Room.RoomName, reservation.StartDate.Format("2006-01-02"),
reservation.EndDate.Format("2006-01-02"))
msg = models.MailData{
To: "me@here.com",
From: "me@here.com",
Subject: "Reservation Notification",
Content: htmlMessage,
}
m.App.MailChan <- msg
m.App.Session.Put(r.Context(), "reservation", reservation)
http.Redirect(w, r, "/reservation-summary", http.StatusSeeOther)

View File

@ -63,8 +63,9 @@ type RoomRestriction struct {
// MailData holds an email message
type MailData struct {
To string
From string
Subject string
Content string
To string
From string
Subject string
Content string
Template string
}