18 Mail
On this page:
18.1 Mailer
make-mailer-factory
mailer?
mailer-sender
mailer-send-email
mailer-send-email-with-template
18.2 Adapters
gen:  mail-adapter
mail-adapter?
mail-adapter-send-email
mail-adapter-send-email-with-template
make-stub-mail-adapter
stub-mail-adapter?
stub-mail-adapter-outbox
18.2.1 Other Adapters

18 Mail🔗

 (require koyo/mail) package: koyo-lib

This module provides functionality for sending e-mail.

18.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 m)  non-empty-string?

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

procedure

(mailer-send-email m    
  #:to to    
  [#:from from]    
  #:subject subject    
  [#:text-content text-content    
  #:html-content html-content])  void?
  m : mailer?
  to : non-empty-string?
  from : non-empty-string? = (mailer-sender m)
  subject : non-empty-string?
  text-content : (or/c #f string?) = #f
  html-content : (or/c #f string?) = #f
Sends an e-mail using the underlying mail adapter.

Added in version 0.8 of package koyo-lib.

procedure

(mailer-send-email-with-template 
  m 
  #:to to 
  [#:from from 
  #:template-id template-id 
  #:template-alias template-alias 
  #:template-model template-model]) 
  void?
  m : mailer?
  to : non-empty-string?
  from : non-empty-string? = (mailer-sender m)
  template-id : (or/c #f exact-positive-integer?) = #f
  template-alias : (or/c #f 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.

18.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 adapter    
  #:to to    
  #:from from    
  #:subject subject    
  [#:text-content text-content    
  #:html-content html-content])  void?
  adapter : mail-adapter?
  to : non-empty-string?
  from : non-empty-string?
  subject : non-empty-string?
  text-content : (or/c #f string?) = #f
  html-content : (or/c #f string?) = #f

procedure

(mail-adapter-send-email-with-template 
  adapter 
  #:to to 
  #:from 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. Adapters must implement at least one of these methods, but they don’t have to implement all of them.

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.

18.2.1 Other Adapters🔗

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