AtlatestRepositorysigil-postmark

sigil-postmark / tree / exampleslive-send.sgl

1;;; Live integration test — sends real email via Postmark.
2;;;
3;;; Requires environment:
4;;; POSTMARK_SERVER_TOKEN — the server API token for David's Postmark
5;;; account (David runs this, don't commit it)
6;;; POSTMARK_FROM — verified sender address
7;;; (default [email protected])
8;;; POSTMARK_TO — recipient address
9;;; (default [email protected])
10;;;
11;;; Run:
12;;; sigil run examples/live-send.sgl
14(import (sigil core)
15 (only (sigil process) getenv)
16 (postmark api))
18(define token
19 (or (getenv "POSTMARK_SERVER_TOKEN")
20 (error "POSTMARK_SERVER_TOKEN must be set")))
22(define from
23 (or (getenv "POSTMARK_FROM") "[email protected]"))
25(define to
26 (or (getenv "POSTMARK_TO") "[email protected]"))
28(define client (postmark-client server-token: token))
30;; Test 1 — single send
31(display "=== Single send ===\n")
32(let ((result (postmark-send client from to
33 "sigil-postmark integration test"
34 text: "This is a plain-text integration test from sigil-postmark."
35 html: (string-append
36 "<h2>sigil-postmark integration test</h2>"
37 "<p>Sent by the <code>sigil-postmark</code> library.</p>"))))
38 (display "Message ID: ") (display (postmark-email-result-message-id result)) (newline)
39 (display "Submitted: ") (display (postmark-email-result-submitted-at result)) (newline)
40 (display "Error code: ") (display (postmark-email-result-error-code result)) (newline)
41 (display "Message: ") (display (postmark-email-result-message result)) (newline))
43;; Test 2 — batch of 2
44(display "\n=== Batch send (2 messages) ===\n")
45(let ((results (postmark-send-batch client
46 (list
47 (build-send-payload from to
48 "sigil-postmark batch 1"
49 text: "Batch message 1")
50 (build-send-payload from to
51 "sigil-postmark batch 2"
52 text: "Batch message 2")))))
53 (for-each
54 (lambda (r)
55 (display "Message ID: ")
56 (display (postmark-email-result-message-id r))
57 (display " Error: ")
58 (display (postmark-email-result-error-code r))
59 (newline))
60 results))
62(display "\nDone!\n")