[[toc]]
Goravel can use facades.Mail()
to easily send mail locally.
Before sending an email, you need to configure the config/mail.go
configuration file.
import "github.com/goravel/framework/contracts/mail"
err := facades.Mail().To([]string{"[email protected]"}).
Cc([]string{"[email protected]"}).
Bcc([]string{"[email protected]"}).
Attach([]string{"file.png"}).
Content(mail.Content{Subject: "Subject", Html: "<h1>Hello Goravel</h1>"}).
Send()
import "github.com/goravel/framework/contracts/mail"
err := facades.Mail().To([]string{"[email protected]"}).
Cc([]string{"[email protected]"}).
Bcc([]string{"[email protected]"}).
Attach([]string{"file.png"}).
Content(mail.Content{Subject: "Subject", Html: "<h1>Hello Goravel</h1>"}).
Queue()
You can also customize the queue:
import "github.com/goravel/framework/contracts/mail"
err := facades.Mail().To([]string{"[email protected]"}).
Cc([]string{"[email protected]"}).
Bcc([]string{"[email protected]"}).
Attach([]string{"file.png"}).
Content(mail.Content{Subject: "Subject", Html: "<h1>Hello Goravel</h1>"}).
Queue(mail.Queue{Connection: "high", Queue: "mail"})
Framework uses MAIL_FROM_ ADDRESS
and MAIL_FROM_ NAME
in the config/mail.go
configuration file as global senders. You can also customize the sender, but you need to note that the mail address needs to be consistent with the configured STMP:
import "github.com/goravel/framework/contracts/mail"
err := facades.Mail().To([]string{"[email protected]"}).
From(mail.From{Address: "[email protected]", Name: "example"}).
Cc([]string{"[email protected]"}).
Bcc([]string{"[email protected]"}).
Attach([]string{"file.png"}).
Content(mail.Content{Subject: "Subject", Html: "<h1>Hello Goravel</h1>"}).
Queue(mail.Queue{Connection: "high", Queue: "mail"})