-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/ReservationConfirm' of https://github.com/geekc…
…amp-vol11-team30/backend into feature/ReservationConfirm
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ package util | |
import ( | ||
"context" | ||
"crypto/rand" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"net/smtp" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -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 | ||
} |