Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (49 sloc) 1.37 KB
package main
import (
type Form struct {
Name string `json:"name"`
Email string `json:"email"`
Message string `json:"message"`
type Payload struct {
Form Form `json:"data"`
type Body struct {
Payload Payload `json:"payload"`
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
// Get information from the data payload.
var body Body
json.Unmarshal([]byte(request.Body), &body)
// Get emails
port, _ := strconv.Atoi(os.Getenv("MAIL_PORT"))
host := os.Getenv("MAIL_HOST")
senderemail := os.Getenv("MAIL_SENDER_EMAIL")
smtppassword := os.Getenv("MAIL_PASSWORD")
smtpuser := os.Getenv("MAIL_USERNAME")
// Send email
m := mail.NewMessage()
m.SetHeader("From", senderemail)
m.SetHeader("Bcc", senderemail)
m.SetHeader("To", body.Payload.Form.Email)
m.SetHeader("Subject", fmt.Sprintf("%s, I received your email!", body.Payload.Form.Name))
m.SetBody("text/plain", body.Payload.Form.Message)
d := mail.NewDialer(host, port, smtpuser, smtppassword)
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: "success!",
}, nil
func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
You can’t perform that action at this time.