본문 바로가기
Programing Language/Golang

[Golang] gomail 이메일 발송

by pcm9881 2023. 1. 7.

설치 

go get gopkg.in/gomail.v2

 

내용 

package utils

import (
   "crypto/tls"
   "gopkg.in/gomail.v2"
)

func SendEmail() {
   m := gomail.NewMessage()
   m.SetHeader("From", "보내는 사람 이메일")
   m.SetHeader("To", "받는 사람 이메일")
   m.SetHeader("Subject", "제목 입니다")
   m.SetBody("text/html", "안녕하세요 HTML을 여기에 적어주세요")

   c := gomail.NewDialer("smtp.gmail.com", 587, "아이디", "비밀번호")
   c.TLSConfig = &tls.Config{InsecureSkipVerify: true}

   if err := c.DialAndSend(m); err != nil {
      panic(err)
   }
}

 

 

 

참조

- gomail 정식문서: https://pkg.go.dev/gopkg.in/gomail.v2

 

gomail package - gopkg.in/gomail.v2 - Go Packages

A daemon that listens to a channel and sends all incoming messages. ch := make(chan *gomail.Message) go func() { d := gomail.NewDialer("smtp.example.com", 587, "user", "123456") var s gomail.SendCloser var err error open := false for { select { case m, ok

pkg.go.dev

- gomail github: https://github.com/go-gomail/gomail

 

GitHub - go-gomail/gomail: The best way to send emails in Go.

The best way to send emails in Go. Contribute to go-gomail/gomail development by creating an account on GitHub.

github.com

 

728x90

'Programing Language > Golang' 카테고리의 다른 글

[Golang] 숫자 문자 변환  (0) 2023.02.06

댓글