@@ -263,6 +263,96 @@ This is a random email body.
263263 t . is ( res . status , 200 ) ;
264264} ) ;
265265
266+ test ( "Multiple allowed senders send_email binding works" , async ( t ) => {
267+ const mf = new Miniflare ( {
268+ modules : true ,
269+ script : SEND_EMAIL_WORKER ,
270+ email : {
271+ send_email : [
272+ {
273+ name : "SEND_EMAIL" ,
274+ allowed_sender_addresses : [
275+ 276+ 277+ ] ,
278+ } ,
279+ ] ,
280+ } ,
281+ compatibilityDate : "2025-03-17" ,
282+ } ) ;
283+
284+ t . teardown ( ( ) => mf . dispose ( ) ) ;
285+
286+ const res = await mf . dispatchFetch (
287+ "http://localhost/?" +
288+ new URLSearchParams ( {
289+ 290+ 291+ } ) . toString ( ) ,
292+ {
293+ body :
`To: someone <[email protected] > 294+ From: someone else <[email protected] > 295+ 296+ MIME-Version: 1.0
297+ Content-Type: text/plain
298+
299+ This is a random email body.
300+ ` ,
301+ method : "POST" ,
302+ }
303+ ) ;
304+
305+ t . is ( await res . text ( ) , "ok" ) ;
306+ t . is ( res . status , 200 ) ;
307+ } ) ;
308+
309+ test ( "Sending email from a sender not in the allowed list does not work" , async ( t ) => {
310+ const mf = new Miniflare ( {
311+ modules : true ,
312+ script : SEND_EMAIL_WORKER ,
313+ email : {
314+ send_email : [
315+ {
316+ name : "SEND_EMAIL" ,
317+ allowed_sender_addresses : [
318+ 319+ 320+ ] ,
321+ } ,
322+ ] ,
323+ } ,
324+ compatibilityDate : "2025-03-17" ,
325+ } ) ;
326+
327+ t . teardown ( ( ) => mf . dispose ( ) ) ;
328+
329+ const res = await mf . dispatchFetch (
330+ "http://localhost/?" +
331+ new URLSearchParams ( {
332+ 333+ 334+ } ) . toString ( ) ,
335+ {
336+ body :
`To: someone <[email protected] > 337+ From: someone else <[email protected] > 338+ 339+ MIME-Version: 1.0
340+ Content-Type: text/plain
341+
342+ This is a random email body.
343+ ` ,
344+ method : "POST" ,
345+ }
346+ ) ;
347+
348+ t . true (
349+ ( await res . text ( ) ) . startsWith (
350+ "Error: email from [email protected] not allowed" 351+ )
352+ ) ;
353+ t . is ( res . status , 500 ) ;
354+ } ) ;
355+
266356test ( "Multiple allowed send_email binding throws if destination is not equal" , async ( t ) => {
267357 const mf = new Miniflare ( {
268358 modules : true ,
0 commit comments