diff --git a/404.html b/404.html index 748319d2..64823242 100644 --- a/404.html +++ b/404.html @@ -18,7 +18,7 @@ - +
diff --git a/assets/js/08133570.197f603c.js b/assets/js/08133570.197f603c.js new file mode 100644 index 00000000..4c98700f --- /dev/null +++ b/assets/js/08133570.197f603c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunk_athenna_docs=self.webpackChunk_athenna_docs||[]).push([[6467],{4918:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>s,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>r,toc:()=>d});var t=i(5893),a=i(1151);const l={title:"Mail",sidebar_position:4,description:"See how to send emails in Athenna."},o="Mail",r={id:"digging-deeper/mail",title:"Mail",description:"See how to send emails in Athenna.",source:"@site/docs/digging-deeper/mail.mdx",sourceDirName:"digging-deeper",slug:"/digging-deeper/mail",permalink:"/docs/digging-deeper/mail",draft:!1,unlisted:!1,editUrl:"https://github.com/AthennaIO/Docs/tree/main/docs/digging-deeper/mail.mdx",tags:[],version:"current",sidebarPosition:4,frontMatter:{title:"Mail",sidebar_position:4,description:"See how to send emails in Athenna."},sidebar:"tutorialSidebar",previous:{title:"Collections",permalink:"/docs/digging-deeper/collections"},next:{title:"Library Development",permalink:"/docs/digging-deeper/library-development"}},s={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Installation",id:"installation",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Available mail drivers",id:"available-mail-drivers",level:3},{value:"Sending mail",id:"sending-mail",level:2},{value:"Sending mail via a specific mailer",id:"sending-mail-via-a-specific-mailer",level:3},{value:"Sending Text and Markdown as content",id:"sending-text-and-markdown-as-content",level:3},{value:"Using view template as content",id:"using-view-template-as-content",level:3},{value:"Previewing mail templates in the browser",id:"previewing-mail-templates-in-the-browser",level:3}];function c(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,a.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h1,{id:"mail",children:"Mail"}),"\n",(0,t.jsx)(n.p,{children:"See how to send emails in Athenna."}),"\n",(0,t.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(n.p,{children:["Sending email doesn't have to be complicated. Athenna provides a\nclean, simple email API powered by the popular ",(0,t.jsx)(n.a,{href:"https://nodemailer.com/",children:"nodemailer"}),"\npackage. Right now Athenna provide drivers for sending email via\nSMTP only, but in the future we will add support for Mailgun,\nMailtrap, Amazon SES, and sendmail."]}),"\n",(0,t.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,t.jsxs)(n.p,{children:["First of all you need to install ",(0,t.jsx)(n.code,{children:"@athenna/mail"})," package\nand configure it. Artisan provides a very simple command to\ninstall and configure the mail library in your project.\nSimply run the following:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"node artisan install @athenna/mail\n"})}),"\n",(0,t.jsx)(n.p,{children:"The mail configurer will do the following operations in\nyour project:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Create the ",(0,t.jsx)(n.code,{children:"mail.ts"})," configuration file."]}),"\n",(0,t.jsxs)(n.li,{children:["Add all mail providers in your ",(0,t.jsx)(n.code,{children:".athennarc.json"})," file."]}),"\n",(0,t.jsxs)(n.li,{children:["Add mail environment variables to ",(0,t.jsx)(n.code,{children:".env"}),", ",(0,t.jsx)(n.code,{children:".env.test"})," and ",(0,t.jsx)(n.code,{children:".env.example"}),"."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"configuration",children:"Configuration"}),"\n",(0,t.jsxs)(n.p,{children:["Athenna's email services may be configured via your application's\n",(0,t.jsx)(n.code,{children:"Path.config('mail.ts')"}),' configuration file. Each mailer configured\nwithin this file may have its own unique configuration and even\nits own unique "transport", allowing your application to use different\nemail services to send certain email messages.']}),"\n",(0,t.jsx)(n.h3,{id:"available-mail-drivers",children:"Available mail drivers"}),"\n",(0,t.jsxs)(n.p,{children:['Each mailer is powered by a "driver". The driver determines how\nthe mail will be transported. The following mail drivers are\navailable in every Athenna application. An entry for most of\nthese drivers is already present in your application\'s\n',(0,t.jsx)(n.code,{children:"Path.config('mail.ts')"})," configuration file, so be sure to\nreview this file to become familiar with its contents:"]}),"\n",(0,t.jsxs)(n.table,{children:[(0,t.jsx)(n.thead,{children:(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.th,{style:{textAlign:"left"},children:"Driver name"}),(0,t.jsx)(n.th,{style:{textAlign:"center"},children:"Website"}),(0,t.jsx)(n.th,{style:{textAlign:"right"},children:"Built with"})]})}),(0,t.jsx)(n.tbody,{children:(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{style:{textAlign:"left"},children:(0,t.jsx)(n.code,{children:"smtp"})}),(0,t.jsx)(n.td,{style:{textAlign:"center"},children:(0,t.jsx)(n.a,{href:"https://nodemailer.com/smtp/",children:"https://nodemailer.com/smtp/"})}),(0,t.jsx)(n.td,{style:{textAlign:"right"},children:(0,t.jsx)(n.a,{href:"https://www.npmjs.com/package/nodemailer",children:"nodemailer"})})]})})]}),"\n",(0,t.jsx)(n.admonition,{type:"note",children:(0,t.jsxs)(n.p,{children:["Athenna has another driver called ",(0,t.jsx)(n.code,{children:"fake"})," that is very helpful when running tests.\nThe ",(0,t.jsx)(n.code,{children:"fake"})," driver got the same signature of all other drivers, but it don't execute\nany operation when calling executors methods like ",(0,t.jsx)(n.code,{children:"send()"}),", which is perfect to use\nwithin the ",(0,t.jsx)(n.a,{href:"/docs/testing/mocking",children:(0,t.jsx)(n.code,{children:"Mock"})})," class. For more information\nabout the ",(0,t.jsx)(n.code,{children:"FakeDriver"}),", take a look at the\n",(0,t.jsx)(n.a,{href:"/docs/testing/mocking#mocking-mail",children:"mocking mail documentation section."})]})}),"\n",(0,t.jsx)(n.h2,{id:"sending-mail",children:"Sending mail"}),"\n",(0,t.jsx)(n.p,{children:"Let's see the simplest way to send a mail using Mail facade:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { Mail } from '@athenna/mail'\n\nawait Mail.from('support@athenna.io')\n .to('user@gmail.com')\n .content('See how to send emails in Athenna.
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 +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.First of all you need to install @athenna/mail
package
and configure it. Artisan provides a very simple command to
@@ -65,34 +65,37 @@
Let's see the simplest way to send a mail using Mail facade:
-import { Mail } from '@athenna/mail'
await Mail.from('support@athenna.io')
.to('user@gmail.com')
.text('Mail content')
.send()
import { Mail } from '@athenna/mail'
await Mail.from('support@athenna.io')
.to('user@gmail.com')
.content('<h1>Mail content</h1>')
.send()
You can add "to", "cc" and "bcc" recipientes by chaining their respective method together:
-await Mail.from('support@athenna.io')
.to('user@gmail.com')
.cc('txsoura@athenna.io')
.bcc('support@athenna.io')
.text('Mail content')
.send()
await Mail.from('support@athenna.io')
.to('user@gmail.com')
.cc('txsoura@athenna.io')
.bcc('support@athenna.io')
.content('<h1>Mail content</h1>')
.send()
By default, Athenna will send email using the mailer configured
as the default
mailer in your application's mail
configuration
file. However, you may use the mailer()
method to send a message
using a specific mailer configuration:
await Mail.mailer('my-mailer')
.from('support@athenna.io')
.to('lenon@athenna.io')
.text('Mail content')
.send()
To send HTML as the content of the mail, you can use the html()
-method:
await Mail.mailer('my-mailer')
.from('support@athenna.io')
.to('lenon@athenna.io')
.html('<h1>Mail content</h1>')
.send()
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')
.send()
await Mail.mailer('my-mailer') 👈
.from('support@athenna.io')
.to('lenon@athenna.io')
.content('Mail content')
.send()
To send text as the content of the mail, you can set the
+type
property in second argument:
await Mail.mailer('my-mailer')
.from('support@athenna.io')
.to('lenon@athenna.io')
.content('Mail content', { type: 'text' }) 👈
.send()
And for markdowns you can use the markdown
type:
await Mail.mailer('my-mailer')
.from('support@athenna.io')
.to('lenon@athenna.io')
.content('# Mail content', { type: 'markdown' }) 👈
.send()
The mail component is integrated with the view component to be
able to render and send a view as the body of the email. To do
so you can use the view()
method of the Mail facade:
const userEmail = 'lenon@athenna.io'
await Mail.from('support@athenna.io')
.to(userEmail)
.view('mail/welcome', { email: userEmail })
.send()
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:
<!-- 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>
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:
Route.get('/mailable', ({ response }) => {
return response.view('mail.welcome', { email: 'lenon@athenna.io' })
})
Route.view()
method,
+allowing you to quickly preview its design without needing to
+send it to an actual email address:
+Route.view('/mailable', 'mail.welcome', { email: 'lenon@athenna.io' })