From a134e8212067d78bcbb134035e3ba6db605fa01a Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Thu, 7 Mar 2024 09:36:11 +0000 Subject: [PATCH 1/2] feat(mail): simplify docs --- docs/digging-deeper/mail.mdx | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/docs/digging-deeper/mail.mdx b/docs/digging-deeper/mail.mdx index e66b0875..8eb66dbe 100644 --- a/docs/digging-deeper/mail.mdx +++ b/docs/digging-deeper/mail.mdx @@ -99,7 +99,7 @@ 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('support@athenna.io') .to('lenon@athenna.io') .text('Mail content') @@ -115,7 +115,7 @@ method: await Mail.mailer('my-mailer') .from('support@athenna.io') .to('lenon@athenna.io') - .html('

Mail content

') + .html('

Mail content

') 👈 .send() ``` @@ -125,7 +125,7 @@ And for markdowns you can use the `markdown()` method: await Mail.mailer('my-mailer') .from('support@athenna.io') .to('lenon@athenna.io') - .markdown('# Mail content') + .markdown('# Mail content') 👈 .send() ``` @@ -140,7 +140,7 @@ const userEmail = 'lenon@athenna.io' await Mail.from('support@athenna.io') .to(userEmail) - .view('mail/welcome', { email: userEmail }) + .view('mail/welcome', { email: userEmail }) 👈 .send() ``` @@ -149,20 +149,10 @@ await Mail.from('support@athenna.io') 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: 'lenon@athenna.io' }) -}) +Route.view('/mailable', 'mail.welcome', { email: 'lenon@athenna.io' }) ``` - - - - - - - - From 5c6f73fe2d0f4c3a33fdc465c3b639327a1108a1 Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Thu, 7 Mar 2024 12:45:16 +0000 Subject: [PATCH 2/2] feat(mail): add new methods --- docs/digging-deeper/mail.mdx | 44 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/docs/digging-deeper/mail.mdx b/docs/digging-deeper/mail.mdx index 8eb66dbe..ce703396 100644 --- a/docs/digging-deeper/mail.mdx +++ b/docs/digging-deeper/mail.mdx @@ -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('support@athenna.io') .to('user@gmail.com') - .text('Mail content') + .content('

Mail content

') .send() ``` @@ -87,7 +87,7 @@ await Mail.from('support@athenna.io') .to('user@gmail.com') .cc('txsoura@athenna.io') .bcc('support@athenna.io') - .text('Mail content') + .content('

Mail content

') .send() ``` @@ -102,30 +102,30 @@ using a specific mailer configuration: await Mail.mailer('my-mailer') 👈 .from('support@athenna.io') .to('lenon@athenna.io') - .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('support@athenna.io') .to('lenon@athenna.io') - .html('

Mail content

') 👈 + .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('support@athenna.io') .to('lenon@athenna.io') - .markdown('# Mail content') 👈 + .content('# Mail content', { type: 'markdown' }) 👈 .send() ``` @@ -140,10 +140,28 @@ const userEmail = 'lenon@athenna.io' await Mail.from('support@athenna.io') .to(userEmail) + .cc('mailer1@athenna.io, mailer2@athenna.io') + .bcc('mailer3@athenna.io, mailer4@athenna.io') + .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')" + +

{{ to }}

+

{{ cc }}

+

{{ bcc }}

+

{{ from }}

+

{{ content }}

+ + +

{{ email }}

+``` + ### Previewing mail templates in the browser When designing a mailable's template, it is convenient to quickly