resend-cli 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,329 @@
1
+ # Workflow Recipes
2
+
3
+ Multi-step recipes for common Resend CLI tasks.
4
+
5
+ ---
6
+
7
+ ## 1. Initial Setup
8
+
9
+ ```bash
10
+ # Install (pick one)
11
+ curl -fsSL https://resend.com/install.sh | bash # Linux / macOS
12
+ npm install -g resend-cli # npm
13
+ brew install resend/cli/resend # Homebrew (macOS / Linux)
14
+ irm https://resend.com/install.ps1 | iex # Windows PowerShell
15
+
16
+ # Authenticate
17
+ resend login --key re_xxx
18
+
19
+ # Verify setup
20
+ resend doctor -q
21
+ ```
22
+
23
+ ---
24
+
25
+ ## 2. Send a Single Email
26
+
27
+ ```bash
28
+ # Basic text email
29
+ resend emails send \
30
+ --from "you@yourdomain.com" \
31
+ --to recipient@example.com \
32
+ --subject "Hello" \
33
+ --text "Body text"
34
+
35
+ # HTML email with attachments
36
+ resend emails send \
37
+ --from "Name <you@yourdomain.com>" \
38
+ --to alice@example.com bob@example.com \
39
+ --subject "Report" \
40
+ --html-file ./email.html \
41
+ --attachment ./report.pdf \
42
+ --cc manager@example.com \
43
+ --reply-to support@yourdomain.com
44
+
45
+ # Scheduled email
46
+ resend emails send \
47
+ --from "you@yourdomain.com" \
48
+ --to recipient@example.com \
49
+ --subject "Reminder" \
50
+ --text "Don't forget!" \
51
+ --scheduled-at "<future-ISO-8601-datetime>"
52
+
53
+ # Check status
54
+ resend emails get <email-id>
55
+
56
+ # Cancel if scheduled
57
+ resend emails cancel <email-id>
58
+ ```
59
+
60
+ ---
61
+
62
+ ## 3. Batch Sending
63
+
64
+ ```bash
65
+ # Create a JSON file with up to 100 emails
66
+ cat > batch.json << 'EOF'
67
+ [
68
+ {"from":"you@domain.com","to":["a@example.com"],"subject":"Hi A","text":"Hello A"},
69
+ {"from":"you@domain.com","to":["b@example.com"],"subject":"Hi B","text":"Hello B"}
70
+ ]
71
+ EOF
72
+
73
+ # Send batch (strict mode: all fail if any invalid)
74
+ resend emails batch --file batch.json --batch-validation strict
75
+
76
+ # Send batch (permissive: partial success allowed)
77
+ resend emails batch --file batch.json --batch-validation permissive
78
+ ```
79
+
80
+ ---
81
+
82
+ ## 4. Domain Setup
83
+
84
+ ```bash
85
+ # Create domain with receiving enabled
86
+ resend domains create --name example.com --region us-east-1 --receiving
87
+
88
+ # Output includes DNS records to configure:
89
+ # - MX records, TXT/DKIM records, SPF, DMARC
90
+ # Configure these in your DNS provider, then:
91
+
92
+ # Trigger verification
93
+ resend domains verify <domain-id>
94
+
95
+ # Check status (repeat until "verified")
96
+ resend domains get <domain-id>
97
+
98
+ # Enable tracking
99
+ resend domains update <domain-id> --open-tracking --click-tracking
100
+ ```
101
+
102
+ ---
103
+
104
+ ## 5. Broadcasts (Bulk Email)
105
+
106
+ ```bash
107
+ # 1. Create a segment
108
+ resend segments create --name "Newsletter Subscribers"
109
+
110
+ # 2. Add contacts to segment
111
+ resend contacts create --email user@example.com --first-name Jane --segment-id <segment-id>
112
+
113
+ # 3. Create and send broadcast
114
+ resend broadcasts create \
115
+ --from "news@yourdomain.com" \
116
+ --subject "Monthly Update" \
117
+ --segment-id <segment-id> \
118
+ --html "<h1>Hello {{{FIRST_NAME|there}}}</h1><p>News content...</p>" \
119
+ --send
120
+
121
+ # Or create as draft first, then send later
122
+ resend broadcasts create \
123
+ --from "news@yourdomain.com" \
124
+ --subject "Monthly Update" \
125
+ --segment-id <segment-id> \
126
+ --html-file ./newsletter.html \
127
+ --name "March Newsletter"
128
+
129
+ resend broadcasts send <broadcast-id>
130
+
131
+ # Schedule for later
132
+ resend broadcasts send <broadcast-id> --scheduled-at "<future-ISO-8601-datetime>"
133
+ ```
134
+
135
+ ---
136
+
137
+ ## 6. Webhook Setup
138
+
139
+ ```bash
140
+ # Create webhook for email delivery events
141
+ resend webhooks create \
142
+ --endpoint https://yourapp.com/webhooks/resend \
143
+ --events email.delivered email.bounced email.complained
144
+
145
+ # IMPORTANT: Save the signing_secret from output — shown once only
146
+
147
+ # Or subscribe to all events
148
+ resend webhooks create \
149
+ --endpoint https://yourapp.com/webhooks/resend \
150
+ --events all
151
+
152
+ # Disable temporarily
153
+ resend webhooks update <webhook-id> --status disabled
154
+
155
+ # Re-enable
156
+ resend webhooks update <webhook-id> --status enabled
157
+
158
+ # Change subscribed events (replaces entire list)
159
+ resend webhooks update <webhook-id> --events email.delivered email.bounced
160
+
161
+ # Local development listener (requires a tunnel like ngrok)
162
+ resend webhooks listen --url https://example.ngrok-free.app
163
+
164
+ # Forward events to your local app
165
+ resend webhooks listen \
166
+ --url https://example.ngrok-free.app \
167
+ --forward-to localhost:3000/webhook
168
+
169
+ # Listen for specific events only
170
+ resend webhooks listen \
171
+ --url https://example.ngrok-free.app \
172
+ --events email.delivered email.bounced
173
+ ```
174
+
175
+ ---
176
+
177
+ ## 7. Profile Management
178
+
179
+ ```bash
180
+ # Add production profile
181
+ resend login --key re_prod_xxx
182
+ # When prompted, name it "production"
183
+
184
+ # Add staging profile
185
+ resend auth switch # or create via login
186
+ resend login --key re_staging_xxx
187
+
188
+ # List profiles
189
+ resend auth list
190
+
191
+ # Switch active profile
192
+ resend auth switch production
193
+
194
+ # Use a profile for a single command
195
+ resend emails list --profile staging
196
+
197
+ # Rename profile
198
+ resend auth rename old-name new-name
199
+
200
+ # Remove profile
201
+ resend auth remove staging
202
+ ```
203
+
204
+ ---
205
+
206
+ ## 8. Templates
207
+
208
+ ```bash
209
+ # Create a template with variables
210
+ resend templates create \
211
+ --name "Welcome Email" \
212
+ --subject "Welcome, {{{NAME}}}!" \
213
+ --html "<h1>Welcome {{{NAME}}}</h1><p>Your plan: {{{PLAN}}}</p>" \
214
+ --from "welcome@yourdomain.com" \
215
+ --alias welcome-email \
216
+ --var NAME:string --var PLAN:string:free
217
+
218
+ # Publish the template
219
+ resend templates publish welcome-email
220
+
221
+ # Duplicate for A/B testing
222
+ resend templates duplicate welcome-email
223
+
224
+ # Update the copy
225
+ resend templates update <new-id> --name "Welcome Email v2" --subject "Hey {{{NAME}}}!"
226
+ ```
227
+
228
+ ---
229
+
230
+ ## 9. Contact & Topic Management
231
+
232
+ ```bash
233
+ # Define custom properties
234
+ resend contact-properties create --key company --type string
235
+ resend contact-properties create --key plan --type string --fallback-value free
236
+
237
+ # Create contacts with properties
238
+ resend contacts create \
239
+ --email user@example.com \
240
+ --first-name Jane \
241
+ --last-name Smith \
242
+ --properties '{"company":"Acme","plan":"pro"}'
243
+
244
+ # Create topics for subscription preferences
245
+ resend topics create --name "Product Updates" --default-subscription opt_in
246
+ resend topics create --name "Marketing" --default-subscription opt_out
247
+
248
+ # Update contact topic subscriptions
249
+ resend contacts update-topics user@example.com \
250
+ --topics '[{"id":"<topic-id>","subscription":"opt_in"}]'
251
+
252
+ # Check subscriptions
253
+ resend contacts topics user@example.com
254
+ ```
255
+
256
+ ---
257
+
258
+ ## 10. CI/CD Integration
259
+
260
+ ```yaml
261
+ # GitHub Actions example
262
+ name: Deploy Notification
263
+ on:
264
+ push:
265
+ branches: [main]
266
+
267
+ env:
268
+ RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
269
+
270
+ jobs:
271
+ notify:
272
+ runs-on: ubuntu-latest
273
+ steps:
274
+ - name: Install Resend CLI
275
+ run: npm install -g resend-cli
276
+
277
+ - name: Send deploy notification
278
+ run: |
279
+ resend emails send \
280
+ --from "deploy@yourdomain.com" \
281
+ --to "team@yourdomain.com" \
282
+ --subject "Deploy: ${{ github.repository }}@${{ github.sha }}" \
283
+ --text "Deployed by ${{ github.actor }} at $(date -u)"
284
+ ```
285
+
286
+ ```bash
287
+ # Generic CI script
288
+ export RESEND_API_KEY=re_xxx
289
+ resend emails send -q \
290
+ --from "ci@yourdomain.com" \
291
+ --to "team@yourdomain.com" \
292
+ --subject "Build complete" \
293
+ --text "Build ${BUILD_ID} passed all tests."
294
+ ```
295
+
296
+ ---
297
+
298
+ ## 11. Inbound Email Processing
299
+
300
+ ```bash
301
+ # Enable receiving on domain (at creation or check existing)
302
+ resend domains create --name example.com --receiving
303
+
304
+ # List received emails
305
+ resend emails receiving list --limit 20
306
+
307
+ # Get full email content
308
+ resend emails receiving get <email-id>
309
+
310
+ # List attachments
311
+ resend emails receiving attachments <email-id>
312
+
313
+ # Get specific attachment download URL
314
+ resend emails receiving attachment <email-id> <attachment-id>
315
+
316
+ # Forward received email
317
+ resend emails receiving forward <email-id> \
318
+ --from "forwarded@yourdomain.com" \
319
+ --to colleague@example.com
320
+
321
+ # Watch for new inbound emails in real time
322
+ resend emails receiving listen
323
+
324
+ # Poll every 10 seconds
325
+ resend emails receiving listen --interval 10
326
+
327
+ # Stream as NDJSON (for scripting)
328
+ resend emails receiving listen --json | head -3
329
+ ```