Skip to content

Commit

Permalink
Merge branch 'feature/ReservationConfirm' of https://github.com/geekc…
Browse files Browse the repository at this point in the history
…amp-vol11-team30/backend into feature/ReservationConfirm
  • Loading branch information
TT-RR committed Sep 22, 2023
2 parents f1796ad + 5e4be09 commit 90c1629
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package util
import (
"context"
"crypto/rand"
"fmt"
"log"
"net/http"
"net/smtp"
"strings"
"time"

Expand Down Expand Up @@ -115,3 +118,25 @@ func MakeRandomStr(digit int) (string, error) {
}
return result, nil
}

func SendMail(id ulid.ULID, password, targetAddrs string) error {
hostname := "smtp.gmail.com" // SMTPサーバーのホスト名
port := 587 // SMTPサーバーのポート番号
from := "[email protected]" // 送信元のメールアドレス
recipients := []string{targetAddrs} // 送信先のメールアドレス
title := "magische 全員回答完了のお知らせ" // メールのタイトル
body := ("全員が回答しました!\n" +
"確認してください!\n") // メールの本文

auth := smtp.PlainAuth("", targetAddrs, password, hostname)
msg := []byte(strings.ReplaceAll(fmt.Sprintf(
"To: %s\nSubject: %s\n\n%s", strings.Join(recipients, ","), title, body),
"\n", "\r\n"))

// メール送信
err := smtp.SendMail(fmt.Sprintf("%s:%d", hostname, port), auth, from, recipients, msg)
if err != nil {
log.Fatal(err)
}
return nil
}

0 comments on commit 90c1629

Please sign in to comment.