smtp
1 Guide
1.1 Sending Emails authenticated by Parameters:
1.2 Sending authenticated Emails by dynamically binding some parameters:
1.3 Sending and authenticating Emails through function arguments:
1.4 Sending html message:
2 Reference
2.1 Parameters
current-smtp-host
current-smtp-port
current-smtp-username
current-smtp-password
current-smtp-body-content-type
current-smtp-debug-mode
2.2 Making and sending mails
make-mail
send-smtp-mail
2.3 Basis Structs
mail
mail?
mail-sender
mail-recipients
mail-cc-recipients
mail-bcc-recipients
mail-subject
mail-attached-files
mail-header
mail-header/  info
mail-header/  body
mail-header/  attachment
3 Others
3.1 TODOs
3.2 Changelogs
3.3 Bug Report
8.1

smtp

Yanying Wang <yanyingwang1@gmail.com>

 (require smtp) package: smtp
A practical library to send emails using SMTP protocol.

1 Guide

1.1 Sending Emails authenticated by Parameters:

> (current-smtp-host "smtp.qq.com")
> (current-smtp-port 587)
> (current-smtp-username "sender1")
> (current-smtp-password "password1")
> (current-smtp-debug-mode #t)
> (define a-mail
    (make-mail "a test email"
               "this is the message body of the test mail"
               #:from "sender1@qq.com"
               #:to '("recipient1@qq.com")
               #:cc '("recipient2@qq.com")
               #:bcc '("recipient3@qq.com" "recipient4@qq.com")
               #:attached-files '("~/abc.txt")))
 
> (define b-mail
    (make-mail "a test1 email"
               "this is the message body of the test1 mail"
               #:from "sender1@qq.com"
               #:to '("recipient1@qq.com")))
 
> (define c-mail
    (make-mail "a test2 email"
               "this is the message body of the test2 mail"
               #:from "sender2@qq.com"
               #:to '("recipient1@qq.com")))
 
> (send-smtp-mail a-mail)
> (send-smtp-mail b-mail)
> (send-smtp-mail c-mail)

1.2 Sending authenticated Emails by dynamically binding some parameters:

> (parameterize ([current-smtp-username "sender2"]
                 [current-smtp-password "password2"])
    (send-smtp-mail c-mail))

1.3 Sending and authenticating Emails through function arguments:

> (send-smtp-mail c-mail
                  #:host "smtp.qq.com"
                  #:port 25
                  #:username "sender2"
                  #:password "password2")

1.4 Sending html message:

> (current-smtp-body-content-type "text/html")
> (define d-mail
    (make-mail "a test of html email"
               "<html><body> <h1>a test of html email</h1> <p>hello world!</p>"
               #:body-content-type "text/html" ;; use #:body-content-type here will overwrite default value from @racket[current-smtp-body-content-type].
               #:from "sender2@qq.com"
               #:to '("recipient1@qq.com")))
 
> (send-smtp-mail d-mail
                  #:host "smtp.qq.com"
                  #:port 25
                  #:username "sender2"
                  #:password "password2")

2 Reference

2.1 Parameters

Check basic info at Racket Parameters.

parameter

(current-smtp-host)  string?

(current-smtp-host v)  void?
  v : string?
 = ""

parameter

(current-smtp-port)  integer?

(current-smtp-port v)  void?
  v : integer?
 = 25

parameter

(current-smtp-username)  string?

(current-smtp-username v)  void?
  v : string?
 = ""

parameter

(current-smtp-password)  string?

(current-smtp-password v)  void?
  v : string?
 = ""
set authentication to be used for sending Emails later, check usage example at Sending Emails authenticated by Parameters:.

parameter

(current-smtp-body-content-type)  string?

(current-smtp-body-content-type v)  void?
  v : string?
 = "text/plain"
current-smtp-body-content-type is used for set smtp mail body’s content type, check usage example at Sending html message:.

parameter

(current-smtp-debug-mode)  boolean?

(current-smtp-debug-mode v)  void?
  v : boolean?
 = #f
current-smtp-debug-mode is used for show status of the smtp auth debug mode or set to show or not show the smtp auth log.

2.2 Making and sending mails

procedure

(make-mail subject    
  message-body    
  [#:from from]    
  #:to to    
  [#:cc cc    
  #:bcc bcc    
  #:attached-files attached-files    
  #:body-content-type body-content-type])  mail?
  subject : string?
  message-body : string?
  from : string? = (current-smtp-username)
  to : (listof string?)
  cc : (listof string?) = '()
  bcc : (listof string?) = '()
  attached-files : (listof (or/c path? string?)) = '()
  body-content-type : string? = (current-smtp-body-content-type)
Make mail struct instances, check usage example at Sending Emails authenticated by Parameters:.

procedure

(send-smtp-mail email    
  [#:host host    
  #:port port    
  #:tls-encode tls-encode    
  #:user username    
  #:password password])  void?
  email : mail?
  host : string? = (current-smtp-host)
  port : integer? = (current-smtp-port)
  tls-encode : boolean? = #f
  username : string? = (current-smtp-username)
  password : string? = (current-smtp-password)
Commit the email sending action, check usage example at Sending and authenticating Emails through function arguments:.

2.3 Basis Structs

struct

(struct mail (sender
    recipients
    cc-recipients
    bcc-recipients
    subject
    message-body
    attached-files))
  sender : string?
  recipients : list?
  cc-recipients : list?
  bcc-recipients : list?
  subject : string?
  message-body : string?
  attached-files : list?
Structure of smtp mails.

procedure

(mail? email)  boolean?

  email : mail

procedure

(mail-sender email)  string?

  email : mail?

procedure

(mail-recipients email)  list?

  email : mail?

procedure

(mail-cc-recipients email)  list?

  email : mail?

procedure

(mail-bcc-recipients email)  list?

  email : mail?

procedure

(mail-subject email)  string?

  email : mail?

procedure

(mail-attached-files email)  list?

  email : mail?
mail? check if email is an instance of struct mail or not.
mail-sender returns struct info about who the email was sent from.
mail-recipients returns struct info about who this email was sent to.
mail-cc-recipients returns struct info about who this email was copied to.
mail-bcc-recipients returns struct info about who this email was carbon copied to.
mail-attached-files returns struct info about a list of attachment file paths of this email.

procedure

(mail-header email)  string?

  email : mail?

procedure

(mail-header/info email)  string?

  email : mail?

procedure

(mail-header/body email)  string?

  email : mail?

procedure

(mail-header/attachment email)  string?

  email : mail?
mail-header returns email header which is used for sending.
mail-header/info returns sender, recipients, subject infos of the mail-header of email.

3 Others

3.1 TODOs

3.2 Changelogs

3.3 Bug Report

Please go to https://github.com/yanyingwang/smtp/issues.