Severell provides a simple API for sending email. Included currently are a few drivers for sending email via SMTP and a Log driver for when in development.
Configuration is made through your .env
file with the following options.
MAIL_DRIVER=Log | SMTP
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_SMTP_SSL= true | fale
MAIL_SMTP_STARTTLS= true | false
First we are going to look at how to configure the "sender" or the from email address.
All you need to do is call the from
method and pass in the sender's email address.
public void index(Mail mail) {
mail.from("example@email.com").text("Hello World!").send();
}
To add a subject to your email simply call the subject
method and pass in the subject.
public void index(Mail mail) {
mail.from("example@email.com")
.text("Hello World!")
.subject("Subject Here")
.send();
}
To send a plain text email you can pass your email body into the text
method.
public void index(Mail mail) {
mail.from("example@email.com")
.text("Hello World!")
.subject("Subject Here")
.send();
}
You are also able to use Mustache templates to send as a HTML email. Simply pass the template
into the template
function.
public void index(Mail mail) {
mail.from("example@email.com")
.template("email.mustache", new HashMap<String, Object>())
.subject("Subject Here")
.send();
}