@@ -0,0 +1,37 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ses"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Region string `json:"region"` // aws region
|
||||
AccessKeyID string `json:"accessKeyID"` // aws accessKeyID
|
||||
SecretAccessKey string `json:"secretAccessKey"` // aws secretAccessKey
|
||||
VerifiedDomain string `json:"verifiedDomain"` // aws verifiedDomain. The sender's email must in this domain.
|
||||
}
|
||||
|
||||
type EmailClient struct {
|
||||
ses *ses.SES
|
||||
}
|
||||
|
||||
var Client *EmailClient
|
||||
|
||||
// MustInit 初始化ses连接
|
||||
func MustInit(ctx context.Context, cfg Config) error {
|
||||
session, err := session.NewSession(&aws.Config{
|
||||
Region: &cfg.Region,
|
||||
Credentials: credentials.NewStaticCredentials(cfg.AccessKeyID, cfg.SecretAccessKey, ""),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
Client = &EmailClient{}
|
||||
Client.ses = ses.New(session)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user