KScript 문서
KO

언어

영어에서 자동 번역되었습니다. 원문은 영어입니다.

메일: KScript.Mail

메일 보내기

@send_mail는 받는 사람, 제목, 본문을 받고, 보낸 메시지를 맵으로 반환합니다:

<import package="KScript.Mail" />

<let name="sent" value="@send_mail(to: 'joan@example.com', subject: 'Your receipt', text: 'Thanks for your order.')" />
<echo value="$sent.subject" />
import KScript.Mail

$sent = @send_mail(to: 'joan@example.com', subject: 'Your receipt', text: 'Thanks for your order.')
echo $sent.subject

to:는 주소 하나, 사용자(email가 있는 모든 맵이나 레코드), 또는 그것들의 리스트를 받습니다. cc:와 bcc:도 같은 방식으로 받고, reply_to:와 from:는 주소 하나만 받습니다:

<import package="KScript.Mail" />

<do>@send_mail(
    to: ['joan@example.com', 'ada@example.com'],
    cc: 'orders@example.com',
    reply_to: 'help@example.com',
    subject: 'Your order has shipped',
    text: 'It is on its way.',
  )</do>
import KScript.Mail

@send_mail(
  to: ['joan@example.com', 'ada@example.com'],
  cc: 'orders@example.com',
  reply_to: 'help@example.com',
  subject: 'Your order has shipped',
  text: 'It is on its way.',
)

본문

메시지에는 본문이 하나만 있습니다: text:, html:, 또는 view:. 둘 이상을 주면 오류입니다. HTML 메일에는 HTML을 표시하지 않는 메일 리더를 위해 그로부터 만든 일반 텍스트 사본이 함께 들어갑니다.

<import package="KScript.Mail" />

<do>@send_mail(to: 'joan@example.com', subject: 'Welcome', html: '&lt;h1>Welcome!&lt;/h1>&lt;p>Thanks for signing up.&lt;/p>')</do>
import KScript.Mail

@send_mail(to: 'joan@example.com', subject: 'Welcome', html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>')

뷰

더 긴 메시지는 페이지처럼 뷰에 두세요. view: 'mail/welcome'는 views/mail/welcome.html(마크다운 메일이라면 .md)를 렌더링하며, data:의 키가 뷰의 변수가 됩니다:

HTML 페이지
<!-- views/mail/welcome.html -->
<h1>Welcome, { $name }</h1>
<p>Your account is ready. <a href="{ $link }">Sign in</a> to get started.</p>
<import package="KScript.Mail" />

<do>@send_mail(to: 'joan@example.com', subject: 'Welcome', view: 'mail/welcome', data: { name: 'Joan', link: 'https://example.com/login' })</do>
import KScript.Mail

@send_mail(to: 'joan@example.com', subject: 'Welcome', view: 'mail/welcome', data: { name: 'Joan', link: 'https://example.com/login' })

kscript make mail welcome --vars name,link이 시작할 뷰를 작성하고, 이를 전송하는 방법을 알려줘요.

첨부 파일

attachments:는 스크립트 또는 파일 값을 기준으로 한 상대 경로의 파일 목록을 받아요:

<import package="KScript.Mail" />

<do>@send_mail(to: 'joan@example.com', subject: 'Your invoice', text: 'It is attached.', attachments: ['invoices/1042.pdf'])</do>
import KScript.Mail

@send_mail(to: 'joan@example.com', subject: 'Your invoice', text: 'It is attached.', attachments: ['invoices/1042.pdf'])

Edit this page on GitHub