mail/js_export.go
2026-06-10 12:41:26 +08:00

57 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package mail
import (
"apigo.cc/go/cast"
"apigo.cc/go/jsmod"
)
func init() {
jsmod.Register("mail", map[string]any{
// 默认邮箱操作 (对齐 PascalCase)
"Send": func(to any, subject, content string, option *SendOption) error {
var toList []string
cast.Convert(&toList, to)
return Send(toList, subject, content, option)
},
"Recv": func(opt *RecvOption) (*RecvResult, error) {
return Recv(opt)
},
// 多实例获取 (对齐 PascalCase支持可选参数)
"Mailbox": func(name *string) *jsMailbox {
target := "default"
if name != nil {
target = *name
}
m := GetMailbox(target)
if m == nil {
return nil
}
return &jsMailbox{m: m}
},
// 辅助工具
"FormatAddr": FormatAddr,
"ParseAddr": ParseAddr,
})
}
// jsMailbox 包装 Mailbox 实例
type jsMailbox struct {
m *Mailbox
}
func (j *jsMailbox) Send(to any, subject, content string, option *SendOption) error {
var toList []string
cast.Convert(&toList, to)
return j.m.Send(toList, subject, content, option)
}
func (j *jsMailbox) Recv(opt *RecvOption) (*RecvResult, error) {
return j.m.Recv(opt)
}
func (j *jsMailbox) Health() error {
return j.m.Health()
}