// Sends post notification mail func SendMail(c appengine.Context, entry Entry) error { config, err := ParseConfig("./config/mailConfig.json") if err != nil { return err } // Prepares email message msg := new(mail.Message) msg.Sender = config.Sender msg.To = make([]string, 1) msg.To[0] = config.To msg.Subject = "New post made from Legacy-BBS-Go" var body bytes.Buffer var mailTemplate = template.Must(template.ParseFiles("template/notificationMailTemplate.txt")) if err := mailTemplate.Execute(&body, entry); err != nil { return err } msg.Body = body.String() if err := mail.Send(c, msg); err != nil { return err } c.Infof("Notification mail sent to \"" + config.To + "\"") return nil }
/** * メールの送信 * @function * @param {appengine.Context} c コンテキスト * @param {string} sender 送信元アドレス * @param {string} to 送信先アドレス * @param {string} subject タイトル * @param {string} body メッセージ */ func sendMail(c appengine.Context, sender string, to string, subject string, body string) { message := new(mail.Message) message.Sender = sender message.To = []string{to} message.Subject = subject message.Body = body err := mail.Send(c, message) check(c, err) }