smtp
1.2 Sending authenticated Emails by dynamically binding some parameters: |
1.3 Sending and authenticating Emails through function arguments: |
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" #:from "sender2@qq.com" #:to '("recipient1@qq.com")))
> (send-smtp-mail d-mail #:host "smtp.qq.com" #:port 25 #:username "sender2" #:password "password2")
1.5 Sending html message with embedding pictures:
> (define f-mail (make-mail "a test of html email" "<html>\n <body>\n <div>\n <p>Taken from wikpedia</p>\n <img src=\"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==\"\n alt=\"Red dot\" />\n </div>\n </body>\n </html>" #:body-content-type "text/html" #:from "sender2@qq.com" #:to '("recipient1@qq.com")))
> (send-smtp-mail f-mail #:host "smtp.qq.com" #:port 25 #:username "sender2" #:password "password2")
2 API
2.1 Parameters
Check basic info at Racket Parameters.
parameter
(current-smtp-host v) → void? v : string?
= ""
parameter
(current-smtp-port v) → void? v : integer?
= 25
parameter
(current-smtp-username v) → void? v : string?
= ""
parameter
(current-smtp-password v) → void? v : string?
= ""
parameter
(current-smtp-body-content-type v) → void? v : string?
= "text/plain"
parameter
(current-smtp-debug-mode v) → void? v : boolean?
= #f
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)
procedure
(send-smtp-mail [ #: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)
2.3 Basis Structs
struct
(struct ( 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?
procedure
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-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/info returns sender, recipients, subject infos of the mail-header of email.