BREAKING CHANGE: The original Go module name was `github.com/ArtalkJS/Artalk`, which has now been modified to `github.com/artalkjs/artalk/v2` (all lowercase). This change may affect the CI pipeline or other areas if you are compiling the Artalk server and have specified the fixed Go module name. Regarding the original `-ldflags -X github.com/ArtalkJS/Artalk/internal/config.Version` and `CommitHash` definitions, please remove them, as they are now obsolete. The `Version` has been hardcoded into the Go code, and the `CommitHash` is now read from the Go build info via runtime/debug’s vcs.revision value. This change only affects the server developers and does not impact the frontend UI client.
36 lines
712 B
Go
36 lines
712 B
Go
package email
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/artalkjs/artalk/v2/internal/config"
|
|
"github.com/artalkjs/artalk/v2/internal/entity"
|
|
)
|
|
|
|
type Email struct {
|
|
FromAddr string
|
|
FromName string
|
|
ToAddr string
|
|
Subject string
|
|
Body string
|
|
LinkedNotify *entity.Notify
|
|
}
|
|
|
|
// Sender is an interface for sending email.
|
|
type Sender interface {
|
|
Send(email *Email) bool
|
|
}
|
|
|
|
func NewSender(conf EmailConf) (Sender, error) {
|
|
switch conf.SendType {
|
|
case config.TypeSMTP:
|
|
return NewSmtpSender(conf.SMTP), nil
|
|
case config.TypeAliDM:
|
|
return NewAliDMSender(conf.AliDM), nil
|
|
case config.TypeSendmail:
|
|
return NewCmdSender(), nil
|
|
default:
|
|
return nil, fmt.Errorf("unknown email sender type")
|
|
}
|
|
}
|