|
49 | 49 | print("Failed to send batch emails") |
50 | 50 | print(f"Error: {err}") |
51 | 51 | exit(1) |
| 52 | + |
| 53 | +try: |
| 54 | + # Send batch emails with permissive validation mode |
| 55 | + print("sending with permissive validation mode") |
| 56 | + |
| 57 | + # Example with some invalid emails to demonstrate error handling |
| 58 | + mixed_params: List[resend.Emails.SendParams] = [ |
| 59 | + { |
| 60 | + "from": "onboarding@resend.dev", |
| 61 | + "to": ["delivered@resend.dev"], |
| 62 | + "subject": "Valid email", |
| 63 | + "html": "<strong>This should work!</strong>", |
| 64 | + }, |
| 65 | + { |
| 66 | + "from": "onboarding@resend.dev", |
| 67 | + "to": [], # Invalid - empty to field |
| 68 | + "subject": "Invalid email", |
| 69 | + "html": "<strong>This should fail!</strong>", |
| 70 | + }, |
| 71 | + ] |
| 72 | + |
| 73 | + options_permissive: resend.Batch.SendOptions = { |
| 74 | + "batch_validation": "permissive", |
| 75 | + } |
| 76 | + |
| 77 | + result: resend.Batch.SendResponse = resend.Batch.send( |
| 78 | + mixed_params, options=options_permissive |
| 79 | + ) |
| 80 | + |
| 81 | + print(f"Successfully sent {len(result['data'])} emails:") |
| 82 | + for email in result["data"]: |
| 83 | + print(f" Email id: {email['id']}") |
| 84 | + |
| 85 | + if "errors" in result and result["errors"]: |
| 86 | + print(f"Validation errors for {len(result['errors'])} emails:") |
| 87 | + for error in result["errors"]: |
| 88 | + print(f" Index {error['index']}: {error['message']}") |
| 89 | + |
| 90 | +except resend.exceptions.ResendError as err: |
| 91 | + print("Failed to send batch emails") |
| 92 | + print(f"Error: {err}") |
| 93 | + exit(1) |
0 commit comments