email-cli 0.1.1

Agent-friendly email CLI for Resend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
use clap::{Args, Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser)]
#[command(
    name = "email-cli",
    version,
    about = "Agent-friendly email CLI for Resend"
)]
pub struct Cli {
    #[arg(long, global = true)]
    pub db: Option<PathBuf>,
    #[arg(long, global = true)]
    pub json: bool,
    #[command(subcommand)]
    pub command: Command,
}

#[derive(Subcommand)]
pub enum Command {
    Profile {
        #[command(subcommand)]
        command: ProfileCommand,
    },
    Account {
        #[command(subcommand)]
        command: AccountCommand,
    },
    Signature {
        #[command(subcommand)]
        command: SignatureCommand,
    },
    Send(SendArgs),
    Reply(ReplyArgs),
    Draft {
        #[command(subcommand)]
        command: DraftCommand,
    },
    Sync(SyncArgs),
    Inbox {
        #[command(subcommand)]
        command: InboxCommand,
    },
    Attachments {
        #[command(subcommand)]
        command: AttachmentsCommand,
    },
    /// Manage Resend domains
    Domain {
        #[command(subcommand)]
        command: DomainCommand,
    },
    /// Manage audiences
    Audience {
        #[command(subcommand)]
        command: AudienceCommand,
    },
    /// Manage contacts within an audience
    Contact {
        #[command(subcommand)]
        command: ContactCommand,
    },
    /// Send batch emails
    Batch {
        #[command(subcommand)]
        command: BatchCommand,
    },
    /// Manage Resend API keys
    ApiKey {
        #[command(subcommand)]
        command: ApiKeyCommand,
    },
    /// Manage the durable send outbox
    Outbox {
        #[command(subcommand)]
        command: OutboxCommand,
    },
    /// Webhook event listener
    Webhook {
        #[command(subcommand)]
        command: WebhookCommand,
    },
    /// View delivery events
    Events {
        #[command(subcommand)]
        command: EventsCommand,
    },
    /// Machine-readable capability manifest
    AgentInfo,
    /// Install skill file to agent platforms
    Skill {
        #[command(subcommand)]
        action: SkillAction,
    },
    /// Generate shell completions
    Completions {
        shell: clap_complete::Shell,
    },
}

#[derive(Subcommand)]
pub enum ProfileCommand {
    Add(ProfileAddArgs),
    #[command(visible_alias = "ls")]
    List,
    Test(ProfileTestArgs),
}

#[derive(Args)]
pub struct ProfileAddArgs {
    pub name: String,
    #[arg(long)]
    pub api_key: Option<String>,
    #[arg(long)]
    pub api_key_env: Option<String>,
    #[arg(long)]
    pub api_key_file: Option<PathBuf>,
    #[arg(long, default_value = "RESEND_API_KEY")]
    pub api_key_name: String,
}

#[derive(Args)]
pub struct ProfileTestArgs {
    pub name: String,
}

#[derive(Subcommand)]
pub enum AccountCommand {
    Add(AccountAddArgs),
    #[command(visible_alias = "ls")]
    List,
    Use(AccountUseArgs),
}

#[derive(Args)]
pub struct AccountAddArgs {
    pub email: String,
    #[arg(long)]
    pub profile: String,
    #[arg(long)]
    pub name: Option<String>,
    #[arg(long)]
    pub signature: Option<String>,
    #[arg(long)]
    pub default: bool,
}

#[derive(Args)]
pub struct AccountUseArgs {
    pub email: String,
}

#[derive(Subcommand)]
pub enum SignatureCommand {
    Set(SignatureSetArgs),
    Show(SignatureShowArgs),
}

#[derive(Args)]
pub struct SignatureSetArgs {
    pub account: String,
    #[arg(long)]
    pub text: String,
}

#[derive(Args)]
pub struct SignatureShowArgs {
    pub account: String,
}

#[derive(Args, Clone)]
pub struct ComposeArgs {
    #[arg(long)]
    pub account: Option<String>,
    #[arg(long, required = true)]
    pub to: Vec<String>,
    #[arg(long)]
    pub cc: Vec<String>,
    #[arg(long)]
    pub bcc: Vec<String>,
    #[arg(long, default_value = "")]
    pub subject: String,
    #[arg(long)]
    pub text: Option<String>,
    #[arg(long)]
    pub text_file: Option<PathBuf>,
    #[arg(long)]
    pub html: Option<String>,
    #[arg(long)]
    pub html_file: Option<PathBuf>,
    #[arg(long = "attach")]
    pub attachments: Vec<PathBuf>,
}

#[derive(Args)]
pub struct SendArgs {
    #[command(flatten)]
    pub compose: ComposeArgs,
}

#[derive(Args)]
pub struct ReplyArgs {
    pub message_id: i64,
    #[arg(long)]
    pub account: Option<String>,
    #[arg(long)]
    pub text: Option<String>,
    #[arg(long)]
    pub text_file: Option<PathBuf>,
    #[arg(long)]
    pub html: Option<String>,
    #[arg(long)]
    pub html_file: Option<PathBuf>,
    #[arg(long = "attach")]
    pub attachments: Vec<PathBuf>,
}

#[derive(Subcommand)]
pub enum DraftCommand {
    #[command(visible_alias = "new")]
    Create(DraftCreateArgs),
    #[command(visible_alias = "ls")]
    List(DraftListArgs),
    Show(DraftShowArgs),
    Send(DraftSendArgs),
    Edit(DraftEditArgs),
    #[command(visible_alias = "rm")]
    Delete(DraftDeleteArgs),
}

#[derive(Args)]
pub struct DraftEditArgs {
    pub id: String,
    #[arg(long)]
    pub subject: Option<String>,
    #[arg(long)]
    pub text: Option<String>,
    #[arg(long)]
    pub html: Option<String>,
    #[arg(long)]
    pub to: Option<Vec<String>>,
    #[arg(long)]
    pub cc: Option<Vec<String>>,
    #[arg(long)]
    pub bcc: Option<Vec<String>>,
}

#[derive(Args)]
pub struct DraftDeleteArgs {
    pub id: String,
}

#[derive(Args)]
pub struct DraftCreateArgs {
    #[command(flatten)]
    pub compose: ComposeArgs,
    #[arg(long)]
    pub reply_to: Option<i64>,
}

#[derive(Args)]
pub struct DraftListArgs {
    #[arg(long)]
    pub account: Option<String>,
}

#[derive(Args)]
pub struct DraftShowArgs {
    pub id: String,
}

#[derive(Args)]
pub struct DraftSendArgs {
    pub id: String,
}

#[derive(Args)]
pub struct SyncArgs {
    #[arg(long)]
    pub account: Option<String>,
    #[arg(long, default_value = "25")]
    pub limit: usize,
    /// Watch for new messages continuously
    #[arg(long)]
    pub watch: bool,
    /// Poll interval in seconds (requires --watch)
    #[arg(long, default_value = "60")]
    pub interval: Option<u64>,
}

#[derive(Subcommand)]
pub enum InboxCommand {
    #[command(visible_alias = "ls")]
    List(InboxListArgs),
    Read(InboxReadArgs),
    #[command(visible_alias = "rm")]
    Delete(InboxDeleteArgs),
    Archive(InboxArchiveArgs),
    Search(InboxSearchArgs),
    Purge(InboxPurgeArgs),
}

#[derive(Args)]
pub struct InboxListArgs {
    #[arg(long)]
    pub account: Option<String>,
    #[arg(long, default_value = "25")]
    pub limit: usize,
    #[arg(long)]
    pub unread: bool,
    #[arg(long)]
    pub archived: bool,
}

#[derive(Args)]
pub struct InboxReadArgs {
    pub id: i64,
    #[arg(long)]
    pub mark_read: bool,
    #[arg(long)]
    pub raw: bool,
}

#[derive(Args)]
pub struct InboxDeleteArgs {
    pub id: i64,
}

#[derive(Args)]
pub struct InboxArchiveArgs {
    pub id: i64,
}

#[derive(Args)]
pub struct InboxSearchArgs {
    pub query: String,
    #[arg(long)]
    pub account: Option<String>,
    #[arg(long, default_value = "25")]
    pub limit: usize,
}

#[derive(Args)]
pub struct InboxPurgeArgs {
    /// Delete messages older than this date (YYYY-MM-DD)
    #[arg(long)]
    pub before: String,
    #[arg(long)]
    pub account: Option<String>,
}

#[derive(Subcommand)]
pub enum AttachmentsCommand {
    #[command(visible_alias = "ls")]
    List(AttachmentListArgs),
    #[command(visible_alias = "show")]
    Get(AttachmentGetArgs),
}

#[derive(Args)]
pub struct AttachmentListArgs {
    pub message_id: i64,
}

#[derive(Args)]
pub struct AttachmentGetArgs {
    pub message_id: i64,
    pub attachment_id: String,
    #[arg(long)]
    pub output: Option<PathBuf>,
}

#[derive(Subcommand)]
pub enum SkillAction {
    /// Write skill file to all detected agent platforms
    Install,
    /// Check which platforms have the skill installed
    Status,
}

// ── Domain commands ────────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum DomainCommand {
    #[command(visible_alias = "ls")]
    List,
    #[command(visible_alias = "show")]
    Get(DomainGetArgs),
    #[command(visible_alias = "new")]
    Create(DomainCreateArgs),
    Verify(DomainVerifyArgs),
    #[command(visible_alias = "rm")]
    Delete(DomainDeleteArgs),
    Update(DomainUpdateArgs),
}

#[derive(Args)]
pub struct DomainGetArgs {
    pub id: String,
}

#[derive(Args)]
pub struct DomainCreateArgs {
    #[arg(long)]
    pub name: String,
    #[arg(long)]
    pub region: Option<String>,
}

#[derive(Args)]
pub struct DomainVerifyArgs {
    pub id: String,
}

#[derive(Args)]
pub struct DomainDeleteArgs {
    pub id: String,
}

#[derive(Args)]
pub struct DomainUpdateArgs {
    pub id: String,
    #[arg(long)]
    pub open_tracking: Option<bool>,
    #[arg(long)]
    pub click_tracking: Option<bool>,
}

// ── Audience commands ──────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum AudienceCommand {
    #[command(visible_alias = "ls")]
    List,
    #[command(visible_alias = "show")]
    Get(AudienceGetArgs),
    #[command(visible_alias = "new")]
    Create(AudienceCreateArgs),
    #[command(visible_alias = "rm")]
    Delete(AudienceDeleteArgs),
}

#[derive(Args)]
pub struct AudienceGetArgs {
    pub id: String,
}

#[derive(Args)]
pub struct AudienceCreateArgs {
    #[arg(long)]
    pub name: String,
}

#[derive(Args)]
pub struct AudienceDeleteArgs {
    pub id: String,
}

// ── Contact commands ───────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum ContactCommand {
    #[command(visible_alias = "ls")]
    List(ContactListArgs),
    #[command(visible_alias = "show")]
    Get(ContactGetArgs),
    #[command(visible_alias = "new")]
    Create(ContactCreateArgs),
    Update(ContactUpdateArgs),
    #[command(visible_alias = "rm")]
    Delete(ContactDeleteArgs),
}

#[derive(Args)]
pub struct ContactListArgs {
    #[arg(long)]
    pub audience: String,
}

#[derive(Args)]
pub struct ContactGetArgs {
    #[arg(long)]
    pub audience: String,
    pub id: String,
}

#[derive(Args)]
pub struct ContactCreateArgs {
    #[arg(long)]
    pub audience: String,
    #[arg(long)]
    pub email: String,
    #[arg(long)]
    pub first_name: Option<String>,
    #[arg(long)]
    pub last_name: Option<String>,
    #[arg(long)]
    pub unsubscribed: Option<bool>,
}

#[derive(Args)]
pub struct ContactUpdateArgs {
    #[arg(long)]
    pub audience: String,
    pub id: String,
    #[arg(long)]
    pub first_name: Option<String>,
    #[arg(long)]
    pub last_name: Option<String>,
    #[arg(long)]
    pub unsubscribed: Option<bool>,
}

#[derive(Args)]
pub struct ContactDeleteArgs {
    #[arg(long)]
    pub audience: String,
    pub id: String,
}

// ── Batch commands ─────────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum BatchCommand {
    Send(BatchSendArgs),
}

#[derive(Args)]
pub struct BatchSendArgs {
    /// Path to a JSON file containing an array of email objects
    #[arg(long)]
    pub file: std::path::PathBuf,
}

// ── API key commands ───────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum ApiKeyCommand {
    #[command(visible_alias = "ls")]
    List,
    #[command(visible_alias = "new")]
    Create(ApiKeyCreateArgs),
    #[command(visible_alias = "rm")]
    Delete(ApiKeyDeleteArgs),
}

#[derive(Args)]
pub struct ApiKeyCreateArgs {
    #[arg(long)]
    pub name: String,
    /// full-access or sending-access
    #[arg(long, default_value = "full-access")]
    pub permission: String,
}

#[derive(Args)]
pub struct ApiKeyDeleteArgs {
    pub id: String,
}

// ── Outbox commands ───────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum OutboxCommand {
    #[command(visible_alias = "ls")]
    List,
    Retry(OutboxRetryArgs),
    Flush,
}

#[derive(Args)]
pub struct OutboxRetryArgs {
    pub id: String,
}

// ── Webhook commands ──────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum WebhookCommand {
    Listen(WebhookListenArgs),
}

#[derive(Args)]
pub struct WebhookListenArgs {
    #[arg(long, default_value = "8080")]
    pub port: u16,
}

// ── Events commands ───────────────────────────────────────────────────────

#[derive(Subcommand)]
pub enum EventsCommand {
    #[command(visible_alias = "ls")]
    List(EventsListArgs),
}

#[derive(Args)]
pub struct EventsListArgs {
    #[arg(long)]
    pub message: Option<i64>,
    #[arg(long, default_value = "50")]
    pub limit: usize,
}