From 510f745e7e77db1b0ecfbd231f38b89b81579f83 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Thu, 23 Apr 2026 20:09:27 +0300 Subject: [PATCH] appview/email: create contact and then add to segment This is API call is idempotent. If the contact doesn't previously exist on Resend, adding to Segment will fail. Signed-off-by: Anirudh Oppiliappan --- appview/email/email.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/appview/email/email.go b/appview/email/email.go index 3ffaa243..052b160f 100644 --- a/appview/email/email.go +++ b/appview/email/email.go @@ -33,10 +33,16 @@ func SendEmail(email Email) error { return nil } -// AddNewsletterContact adds an email address to the Resend newsletter segment. +// AddNewsletterContact creates a global contact in Resend and adds them to the newsletter segment. func AddNewsletterContact(apiKey, segmentID, emailAddr string) error { client := resend.NewClient(apiKey) - _, err := client.Contacts.Segments.Add(&resend.AddContactSegmentRequest{ + _, err := client.Contacts.Create(&resend.CreateContactRequest{ + Email: emailAddr, + }) + if err != nil { + return fmt.Errorf("error creating contact: %w", err) + } + _, err = client.Contacts.Segments.Add(&resend.AddContactSegmentRequest{ SegmentId: segmentID, Email: emailAddr, }) -- 2.51.2