parent
5c07583ba4
commit
f9b94f8101
@ -1,15 +1,34 @@ |
|||||||
package features_email |
package features_email |
||||||
|
|
||||||
import ( |
import ( |
||||||
|
email "MY/webapp/common/email" |
||||||
|
"context" |
||||||
"github.com/gofiber/fiber/v2" |
"github.com/gofiber/fiber/v2" |
||||||
|
. "MY/webapp/common" |
||||||
) |
) |
||||||
|
|
||||||
func GetApiExample(c *fiber.Ctx) error { |
func PostApiEmailSend(c *fiber.Ctx) error { |
||||||
tables := []string{"To", "From"} |
ctx := context.Background() |
||||||
|
|
||||||
return c.JSON(tables) |
msg := email.EmailMessage{ |
||||||
|
To: c.FormValue("To"), |
||||||
|
From: c.FormValue("From"), |
||||||
|
Subject: c.FormValue("Subject"), |
||||||
|
Text: c.FormValue("Message"), |
||||||
|
HTML: c.FormValue("Message"), |
||||||
|
} |
||||||
|
|
||||||
|
sender := email.NewSender(ctx, email.Config{ |
||||||
|
RedisHostPort: "127.0.0.1:6379", |
||||||
|
}) |
||||||
|
defer sender.Close() |
||||||
|
|
||||||
|
err := sender.QueueEmail(msg) |
||||||
|
if err != nil { return IfErrNil(err, c) } |
||||||
|
|
||||||
|
return c.Redirect("/email/") |
||||||
} |
} |
||||||
|
|
||||||
func SetupApi(app *fiber.App) { |
func SetupApi(app *fiber.App) { |
||||||
app.Get("/api/email/send", GetApiExample) |
app.Post("/api/email/send", PostApiEmailSend) |
||||||
} |
} |
||||||
|
|||||||
@ -1,3 +1,21 @@ |
|||||||
<h1>email</h1> |
<h1>Send An Email</h1> |
||||||
|
|
||||||
<p>Replace me.</p> |
|
||||||
|
<form action="/api/email/send" method="POST"> |
||||||
|
<block> |
||||||
|
<label for="To">To:</label> |
||||||
|
<input id="To" name="To"> |
||||||
|
|
||||||
|
<label for="From">From:</label> |
||||||
|
<input id="From" name="From"> |
||||||
|
|
||||||
|
<label for="Subject">Subject:</label> |
||||||
|
<input id="Subject" name="Subject"> |
||||||
|
|
||||||
|
<label for="Message">Message</label> |
||||||
|
|
||||||
|
<textarea id="Message" name="Message" cols="80" rows="10"></textarea> |
||||||
|
|
||||||
|
<input type="submit" value="Send!"> |
||||||
|
</block> |
||||||
|
</form> |
||||||
|
|||||||
Loading…
Reference in new issue