github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/pkg/emailer/init.go (about) 1 package emailer 2 3 import ( 4 "github.com/cozy/cozy-stack/model/instance" 5 "github.com/cozy/cozy-stack/model/job" 6 ) 7 8 var service *EmailerService 9 10 // Emailer allows to send a pre-formatted email to an instance owner. 11 // 12 // This interface has several implementations: 13 // - [EmailerService] sending email via an async job 14 // - [Mock] with a mock implementation 15 type Emailer interface { 16 SendEmail(inst *instance.Instance, cmd *TransactionalEmailCmd) error 17 SendPendingEmail(inst *instance.Instance, cmd *TransactionalEmailCmd) error 18 SendCampaignEmail(inst *instance.Instance, cmd *CampaignEmailCmd) error 19 } 20 21 // Init the emailer package by setting up a service based on the 22 // global config and setup the global functions. 23 func Init() *EmailerService { 24 service = NewEmailerService(job.System()) 25 26 return service 27 } 28 29 // SendEmail send a mail to the instance owner. 30 // 31 // Deprecated: use [EmailerService.SendEmail] instead. 32 func SendEmail(inst *instance.Instance, cmd *TransactionalEmailCmd) error { 33 return service.SendEmail(inst, cmd) 34 }