1 Guide
2 API
2API
9.0
top
← prev up next →

smtpπŸ”— i

Yanying Wang <yanyingwang1@gmail.com>

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

1GuideπŸ”— i

1.1Sending Emails authenticated by Parameters:πŸ”— i

> (current-smtp-host "smtp.qq.com")

> (current-smtp-username "sender1")

> (current-smtp-password "password1")

> (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.2Sending authenticated Emails by dynamically binding some parameters:πŸ”— i

[current-smtp-password "password2"])
(send-smtp-mail c-mail))

1.3Sending and authenticating Emails through function arguments:πŸ”— i

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

1.4Sending html message:πŸ”— i

> (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"
#:port25
#:username"sender2"
#:password"password2")

1.5Sending html message with embedding pictures:πŸ”— i

Since most nowadays modern browsers have already supported the Data URLs, we can just directly embed our pictures in the html content and send it:
> (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==\"\nalt=\"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"
#:port25
#:username"sender2"
#:password"password2")

2APIπŸ”— i

2.1ParametersπŸ”— i

Check basic info at Racket Parameters.

set authentication to be used for sending Emails later, check usage example at Sending Emails authenticated by Parameters:.

current-smtp-body-content-type is used for set smtp mail body’s content type, check usage example at Sending html message:.

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.2Making and sending mailsπŸ”— i

procedure

( make-mail subject
message-body
[ #:fromfrom]
#:toto
[ #:cccc
#:bccbcc
#:attached-filesattached-files
#:body-content-typebody-content-type])mail?
subject:string?
message-body:string?
to:(listofstring? )
cc:(listofstring? )='()
bcc:(listofstring? )='()
attached-files:(listof(or/cpath? string? ))='()
Make mail struct instances, check usage example at Sending Emails authenticated by Parameters:.

procedure

( send-smtp-mail email
[ #:hosthost
#:portport
#:tls-encodetls-encode
#:userusername
#:passwordpassword])void?
email:mail?
tls-encode:boolean? =#f
Commit the email sending action, check usage example at Sending and authenticating Emails through function arguments:.

2.3Basis StructsπŸ”— i

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.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /