smtp
1 Example
2 Reference
current-smtp-debug-mode
current-smtp-host
current-smtp-port
current-smtp-username
current-smtp-password
make-mail
send-smtp-mail
mail
mail?
mail-sender
mail-recipients
mail-subject
mail-message-body
mail-attached-files
mail-header/  info
mail-header/  message-body
mail-header/  attachment
mail-header
3 Bug Report
4 TODO
7.7

smtp

Yanying Wang <yanyingwang1@gmail.com>

 (require smtp) package: smtp

A practical library to send emails using SMTP protocol, Source Code.

    1 Example

    2 Reference

    3 Bug Report

    4 TODO

1 Example

(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)
 
;; below code will do the sending with a different specified auth:
(send-smtp-mail c-mail
                #:host "smtp.qq.com"
                #:port "25"
                #:username "sender2"
                #:password "password2")
 
;; below code will do the samething as the previous code:
(parameterize ([current-smtp-username "sender2"]
               [current-smtp-password "password2"])
  (send-smtp-mail c-mail))
 

2 Reference

parameter

(current-smtp-debug-mode)  boolean?

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

parameter

(current-smtp-host)  string?

(current-smtp-host v)  void?
  v : string?
 = ""
set global smtp auth host.

parameter

(current-smtp-port)  integer?

(current-smtp-port v)  void?
  v : integer?
 = 25
set global smtp auth port number.

parameter

(current-smtp-username)  string?

(current-smtp-username v)  void?
  v : string?
 = ""
set global smtp auth username.

parameter

(current-smtp-password)  string?

(current-smtp-password v)  void?
  v : string?
 = ""
set global smtp auth password.

procedure

(make-mail subject    
  message-body    
  [#:from from]    
  #:to to    
  [#:cc cc    
  #:bcc bcc    
  #:attached-files attached-files])  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?)) = '()
make a mail struct instance.

procedure

(send-smtp-mail email    
  [#:host host    
  #:port port    
  #:user username    
  #:password password])  void?
  email : mail?
  host : string? = (current-smtp-host)
  port : integer? = (current-smtp-port)
  username : string? = (current-smtp-username)
  password : string? = (current-smtp-password)
commit the email sending action.

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?
A structure type for smtp mails.

procedure

(mail? email)  boolean?

  email : mail
check if email is an instance of struct mail or not.

procedure

(mail-sender email)  string?

  email : mail?
returns info about who the email was sent from.

procedure

(mail-recipients email)  list?

  email : mail?
returns info about who this email was sent to.

procedure

(mail-subject email)  string?

  email : mail?
returns the email subject.

procedure

(mail-message-body email)  string?

  email : mail?
returns the email content.

procedure

(mail-attached-files email)  list?

  email : mail?
returns a list of the email attachment file paths.

procedure

(mail-header/info email)  string?

  email : mail?
returns sender, recipients, subject infos of the email.

procedure

(mail-header/message-body email)  string?

  email : mail?
returns message body of the email.

procedure

(mail-header/attachment email)  string?

  email : mail?
returns encoded attachment content of the email.

procedure

(mail-header email)  string?

  email : mail?
returns header of the email.

3 Bug Report

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

4 TODO