Functional Weave
Code in Rust

email.send@1.0.0

contracts.json

10,400 bytes · view raw

[
  {"name":"log: writes one line and sends nothing","provider":"log","env":{"EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Reset your password","text":"Hello Ada,\n\nSomeone asked to reset your password. Follow https://acme.example/reset?t=abc123 within an hour, or ignore this email.\n\nAcme"}],"logs":["email log-000102030405 from Acme <hello@acme.example> to ada@example.com: Reset your password | Hello Ada, Someone asked to reset your password. Follow http"],"expect":{"provider":"log","id":"log-000102030405"}},
  {"name":"log: an html-only message from its own sender, with cc and bcc","provider":"log","random":"a1b2c3d4e5f6","args":[{"to":["Grace <grace@example.com>"],"cc":["team@acme.example"],"bcc":["audit@acme.example"],"from":"Support <support@acme.example>","subject":"Welcome","html":"<p>Welcome to <b>Acme</b>, Grace.</p>"}],"logs":["email log-a1b2c3d4e5f6 from Support <support@acme.example> to Grace <grace@example.com>, cc team@acme.example, bcc audit@acme.example: Welcome | <p>Welcome to <b>Acme</b>, Grace.</p>"],"expect":{"provider":"log","id":"log-a1b2c3d4e5f6"}},
  {"name":"resend: posts the message and returns Resend's id","provider":"resend","env":{"RESEND_API_KEY":"re_test_123456789","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["grace@example.com"],"subject":"Welcome","text":"Welcome to Acme, Grace.","html":"<p>Welcome to <b>Acme</b>, Grace.</p>","replyTo":"help@acme.example"}],"exchanges":[{"request":{"method":"POST","url":"https://api.resend.com/emails","headers":{"authorization":"Bearer re_test_123456789","content-type":"application/json"},"json":{"from":"Acme <hello@acme.example>","to":["grace@example.com"],"subject":"Welcome","text":"Welcome to Acme, Grace.","html":"<p>Welcome to <b>Acme</b>, Grace.</p>","reply_to":"help@acme.example"}},"response":{"status":200,"json":{"id":"49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"}}}],"expect":{"provider":"resend","id":"49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"}},
  {"name":"resend: a refused message is thrown with Resend's reason","provider":"resend","env":{"RESEND_API_KEY":"re_test_123456789"},"args":[{"to":["grace@example.com"],"from":"Acme <hello@unverified.example>","subject":"Welcome","text":"Welcome to Acme, Grace."}],"exchanges":[{"request":{"method":"POST","url":"https://api.resend.com/emails","json":{"from":"Acme <hello@unverified.example>","to":["grace@example.com"],"subject":"Welcome","text":"Welcome to Acme, Grace."}},"response":{"status":422,"json":{"statusCode":422,"name":"validation_error","message":"The unverified.example domain is not verified."}}}],"expectError":"resend refused the email (422 validation_error): The unverified.example domain is not verified."},
  {"name":"resend: a bad key says which variable to fix","provider":"resend","env":{"RESEND_API_KEY":"re_test_revoked","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["grace@example.com"],"subject":"Welcome","text":"Welcome to Acme, Grace."}],"exchanges":[{"request":{"method":"POST","url":"https://api.resend.com/emails","headers":{"authorization":"Bearer re_test_revoked"}},"response":{"status":401,"json":{"statusCode":401,"name":"validation_error","message":"API key is invalid"}}}],"expectError":"resend refused RESEND_API_KEY (401): API key is invalid"},
  {"name":"resend: no key set","provider":"resend","env":{"EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["grace@example.com"],"subject":"Welcome","text":"Welcome to Acme, Grace."}],"expectError":"RESEND_API_KEY is not set"},
  {"name":"smtp: implicit TLS on 465, one recipient, a text body","provider":"smtp","env":{"SMTP_URL":"smtps://apikey:s3cret%21@smtp.mail.example:465","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Reset your password","text":"Hello Ada,\n\nSomeone asked to reset your password. Follow https://acme.example/reset?t=abc123 within an hour, or ignore this email.\n\nAcme"}],"exchanges":[{"connect":{"host":"smtp.mail.example","port":465,"tls":true},"dialogue":[{"server":"220 smtp.mail.example ESMTP ready"},{"client":"EHLO acme.example"},{"server":["250-smtp.mail.example","250-AUTH PLAIN LOGIN","250 8BITMIME"]},{"client":"AUTH PLAIN AGFwaWtleQBzM2NyZXQh"},{"server":"235 2.7.0 Authentication successful"},{"client":"MAIL FROM:<hello@acme.example>"},{"server":"250 2.1.0 Ok"},{"client":"RCPT TO:<ada@example.com>"},{"server":"250 2.1.5 Ok"},{"client":"DATA"},{"server":"354 End data with <CR><LF>.<CR><LF>"},{"client":["From: Acme <hello@acme.example>","To: ada@example.com","Subject: Reset your password","Date: Thu, 01 Jan 2026 00:00:00 +0000","Message-ID: <000102030405060708090a0b0c0d0e0f@acme.example>","MIME-Version: 1.0","Content-Type: text/plain; charset=utf-8","Content-Transfer-Encoding: base64","","SGVsbG8gQWRhLAoKU29tZW9uZSBhc2tlZCB0byByZXNldCB5b3VyIHBhc3N3b3JkLiBGb2xsb3cg","aHR0cHM6Ly9hY21lLmV4YW1wbGUvcmVzZXQ/dD1hYmMxMjMgd2l0aGluIGFuIGhvdXIsIG9yIGln","bm9yZSB0aGlzIGVtYWlsLgoKQWNtZQ==","."]},{"server":"250 2.0.0 Ok: queued as 4F9A2C"},{"client":"QUIT"},{"server":"221 2.0.0 Bye"}]}],"expect":{"provider":"smtp","id":"4F9A2C"}},
  {"name":"smtp: STARTTLS on 587, text and html, cc and bcc, a non-ASCII subject","provider":"smtp","env":{"SMTP_URL":"smtp://apikey:s3cret%21@smtp.mail.example:587","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["Grace <grace@example.com>"],"cc":["team@acme.example"],"bcc":["audit@acme.example"],"subject":"Bienvenue, café ☕","text":"Welcome to Acme, Grace.","html":"<p>Welcome to <b>Acme</b>, Grace.</p>","replyTo":"help@acme.example"}],"exchanges":[{"connect":{"host":"smtp.mail.example","port":587,"tls":false},"dialogue":[{"server":"220 smtp.mail.example ESMTP ready"},{"client":"EHLO acme.example"},{"server":["250-smtp.mail.example","250-STARTTLS","250 8BITMIME"]},{"client":"STARTTLS"},{"server":"220 2.0.0 Ready to start TLS"},{"starttls":"smtp.mail.example"},{"client":"EHLO acme.example"},{"server":["250-smtp.mail.example","250-AUTH PLAIN LOGIN","250 8BITMIME"]},{"client":"AUTH PLAIN AGFwaWtleQBzM2NyZXQh"},{"server":"235 2.7.0 Authentication successful"},{"client":"MAIL FROM:<hello@acme.example>"},{"server":"250 2.1.0 Ok"},{"client":"RCPT TO:<grace@example.com>"},{"server":"250 2.1.5 Ok"},{"client":"RCPT TO:<team@acme.example>"},{"server":"250 2.1.5 Ok"},{"client":"RCPT TO:<audit@acme.example>"},{"server":"250 2.1.5 Ok"},{"client":"DATA"},{"server":"354 End data with <CR><LF>.<CR><LF>"},{"client":["From: Acme <hello@acme.example>","To: Grace <grace@example.com>","Cc: team@acme.example","Reply-To: help@acme.example","Subject: =?UTF-8?B?QmllbnZlbnVlLCBjYWbDqSDimJU=?=","Date: Thu, 01 Jan 2026 00:00:00 +0000","Message-ID: <000102030405060708090a0b0c0d0e0f@acme.example>","MIME-Version: 1.0","Content-Type: multipart/alternative; boundary=\"fune-0001020304050607\"","","--fune-0001020304050607","Content-Type: text/plain; charset=utf-8","Content-Transfer-Encoding: base64","","V2VsY29tZSB0byBBY21lLCBHcmFjZS4=","--fune-0001020304050607","Content-Type: text/html; charset=utf-8","Content-Transfer-Encoding: base64","","PHA+V2VsY29tZSB0byA8Yj5BY21lPC9iPiwgR3JhY2UuPC9wPg==","--fune-0001020304050607--","."]},{"server":"250 2.0.0 OK id=1qX9-0004Ab-Cd"},{"client":"QUIT"},{"server":"221 2.0.0 Bye"}]}],"expect":{"provider":"smtp","id":"<000102030405060708090a0b0c0d0e0f@acme.example>"}},
  {"name":"smtp: a refused login is thrown with the server's reply","provider":"smtp","env":{"SMTP_URL":"smtps://apikey:s3cret%21@smtp.mail.example:465","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Hi","text":"Hi"}],"exchanges":[{"connect":{"host":"smtp.mail.example","port":465,"tls":true},"dialogue":[{"server":"220 smtp.mail.example ESMTP ready"},{"client":"EHLO acme.example"},{"server":["250-smtp.mail.example","250-AUTH PLAIN LOGIN","250 8BITMIME"]},{"client":"AUTH PLAIN AGFwaWtleQBzM2NyZXQh"},{"server":"535 5.7.8 Authentication credentials invalid"}]}],"expectError":"smtp: AUTH PLAIN was answered 535 5.7.8 Authentication credentials invalid"},
  {"name":"smtp: a server without STARTTLS on 587 is refused before the password is sent","provider":"smtp","env":{"SMTP_URL":"smtp://apikey:s3cret%21@smtp.mail.example:587","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Hi","text":"Hi"}],"exchanges":[{"connect":{"host":"smtp.mail.example","port":587,"tls":false},"dialogue":[{"server":"220 smtp.mail.example ESMTP"},{"client":"EHLO acme.example"},{"server":["250-smtp.mail.example","250 AUTH PLAIN"]}]}],"expectError":"does not offer STARTTLS, and the password is never sent in the clear"},
  {"name":"no provider chosen","env":{"EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Hi","text":"Hi"}],"expectError":"EMAIL_PROVIDER is not set; set it to one of resend, smtp, log"},
  {"name":"an unknown provider","env":{"EMAIL_PROVIDER":"sendgrid","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Hi","text":"Hi"}],"expectError":"EMAIL_PROVIDER is \"sendgrid\"; set it to one of resend, smtp, log"},
  {"name":"a recipient that is not an address is refused before sending","provider":"log","env":{"EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada at example dot com"],"subject":"Hi","text":"Hi"}],"expectError":"to \"ada at example dot com\" is not an email address"},
  {"name":"no recipients","provider":"log","env":{"EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":[],"subject":"Hi","text":"Hi"}],"expectError":"an email needs at least one recipient"},
  {"name":"no body","provider":"resend","env":{"RESEND_API_KEY":"re_test_123456789","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Hi"}],"expectError":"an email needs a text or an html body"},
  {"name":"no From address anywhere","provider":"smtp","env":{"SMTP_URL":"smtps://apikey:s3cret%21@smtp.mail.example:465"},"args":[{"to":["ada@example.com"],"subject":"Hi","text":"Hi"}],"expectError":"no From address: give message.from, or set EMAIL_FROM"},
  {"name":"a subject with a line break is refused (header injection)","provider":"smtp","env":{"SMTP_URL":"smtps://apikey:s3cret%21@smtp.mail.example:465","EMAIL_FROM":"Acme <hello@acme.example>"},"args":[{"to":["ada@example.com"],"subject":"Hi\r\nBcc: everyone@example.com","text":"Hi"}],"expectError":"the subject is one line of text"}
]