17 Mail
On this page:
17.1 Mailer
make-mailer-factory
mailer?
mailer-sender
mailer-send-email-with-template
17.2 Adapters
gen:  mail-adapter
mail-adapter?
mail-adapter-send-email-with-template
make-stub-mail-adapter
stub-mail-adapter?
stub-mail-adapter-outbox
17.2.1 Other Adapters

17 Mail

 (require koyo/mail) package: koyo-lib

This module provides functionality for sending e-mail.

17.1 Mailer

The mailer is a component that wraps a mail-adapter? along with a default value for the sender and common variables for some of the template model properties.

procedure

(make-mailer-factory #:adapter adapter 
  #:sender sender 
  #:common-variables common-variables) 
  (-> mailer?)
  adapter : mail-adapter?
  sender : non-empty-string?
  common-variables : (hash/c symbol? string?)
Returns a function that creates a new mailer? when called.

procedure

(mailer? v)  boolean?

  v : any/c
Returns #t when v is a mailer.

procedure

(mailer-sender mailer)  non-empty-string?

  mailer : mailer?
Returns the default sender e-mail address the mailer was created with.

procedure

(mailer-send-email-with-template 
  mailer 
  #:to to 
  [#:from from 
  #:template-id template-id 
  #:template-alias template-alias 
  #:template-model template-model]) 
  void?
  mailer : mailer?
  to : non-empty-string?
  from : non-empty-string? = (mailer-sender mailer)
  template-id : (or/c false/c exact-positive-integer?) = #f
  template-alias : (or/c false/c symbol?) = #f
  template-model : (hash/c symbol? string?) = (hasheq)
Sends a templated e-mail using the underlying mail adapter.

The #:template-model hash is merged with the #:common-variables the mailer was created with prior to being passed to mail-adapter-send-email-with-template.

17.2 Adapters

Mail adapters expose a consistent interface for values that can send e-mail.

interface

gen:mail-adapter

procedure

(mail-adapter? v)  boolean?

  v : any/c

procedure

(mail-adapter-send-email-with-template 
  adapter 
  #:to to 
  #:form from 
  [#:template-id template-id 
  #:template-alias template-alias] 
  #:template-model template-model) 
  void?
  adapter : mail-adapter?
  to : non-empty-string?
  from : non-empty-string?
  template-id : (or/c exact-positive-integer?) = #f
  template-alias : (or/c symbol?) = #f
  template-model : (hash/c symbol? string?)
The generic interface for mail adapters.

The #:template-id and #:template-alias arguments to mail-adapter-send-email-with-template are mutually exclusive.

procedure

(make-stub-mail-adapter)  mail-adapter?

procedure

(stub-mail-adapter? v)  boolean?

  v : any/c

procedure

(stub-mail-adapter-outbox adapter)  (listof hash?)

  adapter : stub-mail-adapter?
A stub mail adapter. All emails are stored in a list called the outbox. The current contents of the outbox can be retrieved using stub-mail-adapter-outbox.

17.2.1 Other Adapters

koyo-postmark provides a mail adapter for interfacing with the Postmark API.