Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 1.96 KB

mail.md

File metadata and controls

68 lines (49 loc) · 1.96 KB

Mail

[[toc]]

Introduction

Goravel can use facades.Mail() to easily send mail locally.

Configuration

Before sending an email, you need to configure the config/mail.go configuration file.

Send Mail

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()

Send Mail By 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()

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"})

Setting Sender

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"})