package util
import (
"fmt"
"net/smtp"
)
type MailStore struct{
}
func(mailStore MailStore) SendMail() bool{
smtpServer := "smtp.qq.com"
smtpPort := 587
senderEmail := "xxxxx@qq.com"
senderPassword := "xxxx"
recipientEmail := "xxx@163.com"
subject := "Hello from Go!"
body := "This is a test email sent from a Go program."
err := sendEmail(smtpServer, smtpPort, senderEmail, senderPassword, recipientEmail, subject, body)
if err != nil {
fmt.Println("Error sending email:", err)
return false
} else {
fmt.Println("Email sent successfully!")
return true
}
}
func sendEmail(smtpServer string, smtpPort int, senderEmail, senderPassword, recipientEmail, subject, body string) error {
auth := smtp.PlainAuth("", senderEmail, senderPassword, smtpServer)
message := []byte("From: "+senderEmail+"\r\n"+"To: " + recipientEmail + "\r\n" +
"Subject: " + subject + "\r\n" +
"\r\n" +
body + "\r\n")
err := smtp.SendMail(smtpServer+":"+fmt.Sprintf("%d", smtpPort), auth, senderEmail, []string{recipientEmail}, message)
if err != nil {
return err
}
return nil
}