2024-03-19 16:20:32 +00:00
|
|
|
package email
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/smtp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EmailConf struct {
|
2024-03-21 17:39:32 +00:00
|
|
|
From string
|
2024-03-19 16:20:32 +00:00
|
|
|
Password string
|
|
|
|
SmtpHost string
|
|
|
|
SmtpPort string
|
|
|
|
}
|
|
|
|
|
2024-03-21 17:39:32 +00:00
|
|
|
func (e *EmailConf) SendEmail(to string, message string) error {
|
2024-03-19 16:20:32 +00:00
|
|
|
messageByte := []byte(message)
|
|
|
|
auth := smtp.PlainAuth("", e.From, e.Password, e.SmtpHost)
|
|
|
|
|
|
|
|
if err := smtp.SendMail(e.SmtpHost+":"+e.SmtpPort, auth, e.From, []string{to}, messageByte); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2024-03-21 17:39:32 +00:00
|
|
|
}
|