카테고리 없음
Golang vol.4
곽빵
2022. 5. 7. 14:43
개요
고랭 학습하면서 느낀점이나 기록하면 좋을법한 내용들을 정리
1. mailhog (SMTP)
sendgrid와 비슷한 로컬 시스템용 SMTP 서버로 go 언어로 구현되어 있는 친구
일단 설치..
brew install mailhog
그리고 실행
URL에 들어가보면
잘 실행중이다.
그럼 서버에서 메일을 보내보자.
이용해야되는건 내 로컬호스트(docker의 로컬이 아닌)에서 구동중인 0.0.0.0:1025의 smtp서버를 이용해야한다.
host.docker.internal -> 이건 docker 컨테이너 안에서 내 컴퓨터의 로컬호스트에 접근한다는 것
ambassadorMessage := []byte(fmt.Sprintf("You earned $%f from the link #%s", ambassadorRevenue, order.Code))
smtp.SendMail("host.docker.internal:1025", nil, "no-reply@email.com", []string{order.AmbassadorEmail}, ambassadorMessage)
adminMessage := []byte(fmt.Sprintf("Order #%d with a total of $%f has been completed", order.Id, adminRevenue))
smtp.SendMail("host.docker.internal:1025", nil, "no-reply@email.com", []string{order.AmbassadorEmail}, adminMessage)
성공!