Skip to content

Commit

Permalink
Merge pull request #600 from wzxjohn/upstream
Browse files Browse the repository at this point in the history
feat: support Azure Comm Service SMTP
  • Loading branch information
Calcium-Ion authored Dec 7, 2024
2 parents 3eca580 + 568d4e3 commit 904a185
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions common/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (
)

func generateMessageID() (string, error) {
split := strings.Split(SMTPAccount, "@")
split := strings.Split(SMTPFrom, "@")
if len(split) < 2 {
return "", fmt.Errorf("invalid SMTP account")
}
domain := strings.Split(SMTPAccount, "@")[1]
domain := strings.Split(SMTPFrom, "@")[1]
return fmt.Sprintf("<%d.%s@%s>", time.Now().UnixNano(), GetRandomString(12), domain), nil
}

func SendEmail(subject string, receiver string, content string) error {
if SMTPFrom == "" { // for compatibility
SMTPFrom = SMTPAccount
}
id, err2 := generateMessageID()
if err2 != nil {
return err2
}
if SMTPFrom == "" { // for compatibility
SMTPFrom = SMTPAccount
}
if SMTPServer == "" && SMTPAccount == "" {
return fmt.Errorf("SMTP 服务器未配置")
}
Expand Down Expand Up @@ -79,11 +79,11 @@ func SendEmail(subject string, receiver string, content string) error {
if err != nil {
return err
}
} else if isOutlookServer(SMTPAccount) {
} else if isOutlookServer(SMTPAccount) || SMTPServer == "smtp.azurecomm.net" {
auth = LoginAuth(SMTPAccount, SMTPToken)
err = smtp.SendMail(addr, auth, SMTPAccount, to, mail)
err = smtp.SendMail(addr, auth, SMTPFrom, to, mail)
} else {
err = smtp.SendMail(addr, auth, SMTPAccount, to, mail)
err = smtp.SendMail(addr, auth, SMTPFrom, to, mail)
}
return err
}

0 comments on commit 904a185

Please sign in to comment.