-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from AthennaIO/develop
feat(mail): add new methods
- Loading branch information
Showing
1 changed file
with
37 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,10 @@ See how to send emails in Athenna. | |
## Introduction | ||
|
||
Sending email doesn't have to be complicated. Athenna provides a | ||
clean, simple email API powered by the popular [nodemailer] package. | ||
Right now Athenna provide drivers for sending email via SMTP, only | ||
but in the future we will add support for Mailgun, Mailtrap, | ||
Amazon SES, and sendmail. | ||
clean, simple email API powered by the popular [nodemailer](https://nodemailer.com/) | ||
package. Right now Athenna provide drivers for sending email via | ||
SMTP only, but in the future we will add support for Mailgun, | ||
Mailtrap, Amazon SES, and sendmail. | ||
|
||
## Installation | ||
|
||
|
@@ -75,7 +75,7 @@ import { Mail } from '@athenna/mail' | |
|
||
await Mail.from('[email protected]') | ||
.to('[email protected]') | ||
.text('Mail content') | ||
.content('<h1>Mail content</h1>') | ||
.send() | ||
``` | ||
|
||
|
@@ -87,7 +87,7 @@ await Mail.from('[email protected]') | |
.to('[email protected]') | ||
.cc('[email protected]') | ||
.bcc('[email protected]') | ||
.text('Mail content') | ||
.content('<h1>Mail content</h1>') | ||
.send() | ||
``` | ||
|
||
|
@@ -99,33 +99,33 @@ file. However, you may use the `mailer()` method to send a message | |
using a specific mailer configuration: | ||
|
||
```typescript | ||
await Mail.mailer('my-mailer') | ||
await Mail.mailer('my-mailer') π | ||
.from('[email protected]') | ||
.to('[email protected]') | ||
.text('Mail content') | ||
.content('Mail content') | ||
.send() | ||
``` | ||
|
||
### Sending HTML and Markdown as content | ||
### Sending Text and Markdown as content | ||
|
||
To send HTML as the content of the mail, you can use the `html()` | ||
method: | ||
To send text as the content of the mail, you can set the | ||
`type` property in second argument: | ||
|
||
```typescript | ||
await Mail.mailer('my-mailer') | ||
.from('[email protected]') | ||
.to('[email protected]') | ||
.html('<h1>Mail content</h1>') | ||
.content('Mail content', { type: 'text' }) π | ||
.send() | ||
``` | ||
|
||
And for markdowns you can use the `markdown()` method: | ||
And for markdowns you can use the `markdown` type: | ||
|
||
```typescript | ||
await Mail.mailer('my-mailer') | ||
.from('[email protected]') | ||
.to('[email protected]') | ||
.markdown('# Mail content') | ||
.content('# Mail content', { type: 'markdown' }) π | ||
.send() | ||
``` | ||
|
||
|
@@ -140,29 +140,37 @@ const userEmail = '[email protected]' | |
|
||
await Mail.from('[email protected]') | ||
.to(userEmail) | ||
.view('mail/welcome', { email: userEmail }) | ||
.cc('[email protected], [email protected]') | ||
.bcc('[email protected], [email protected]') | ||
.content('This is the mail body') | ||
.view('mail/welcome', { email: userEmail }) π | ||
.send() | ||
``` | ||
|
||
Any data that you provide using the `Mail` facade will be | ||
available to you in your view: | ||
|
||
```html title="Path.views('mail/welcome.edge')" | ||
<!-- Provided by you also but using Mail facade --> | ||
<h1>{{ to }}</h1> | ||
<h1>{{ cc }}</h1> | ||
<h1>{{ bcc }}</h1> | ||
<h1>{{ from }}</h1> | ||
<h1>{{ content }}</h1> | ||
|
||
<!-- Provided by you in second argument --> | ||
<h1>{{ email }}</h1> | ||
``` | ||
|
||
### Previewing mail templates in the browser | ||
|
||
When designing a mailable's template, it is convenient to quickly | ||
preview the rendered mailable in your browser like a typical | ||
Edge template. For this reason, Athenna allows you to return any | ||
mailable directly from a route closure or controller by using the | ||
`response.view()` method, allowing you to quickly preview its | ||
design without needing to send it to an actual email address: | ||
mailable directly from a route using the `Route.view()` method, | ||
allowing you to quickly preview its design without needing to | ||
send it to an actual email address: | ||
|
||
```typescript title="Path.routes('http.ts')" | ||
Route.get('/mailable', ({ response }) => { | ||
return response.view('mail.welcome', { email: '[email protected]' }) | ||
}) | ||
Route.view('/mailable', 'mail.welcome', { email: '[email protected]' }) | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|