दस्तावेज़ पर जाएँ
Go

ईमेल भेजें

एक संदेश अभी या बाद में, अटैचमेंट के साथ, या एक ही अनुरोध में सौ संदेश।

एक संदेश भेजें

send.go
sent, err := client.Emails.Send(ctx, openemail.Body{	"from":    "Acme Billing <[email protected]>",	"to":      []string{"[email protected]", "[email protected]"},	"replyTo": "[email protected]",	"subject": "Your September invoice",	"html":    "<p>The invoice is attached.</p>",	"text":    "The invoice is attached.",	"tags":    openemail.Body{"invoice": "inv_2026_09_4192"},})if err != nil {	return err} fmt.Println(sent.ID(), sent.String("status"))

to, cc और bcc एक पता या एक सूची लेते हैं, और पता Ada <[email protected]> जैसा टेक्स्ट होता है या email और name वाला map। बॉडी html और text से, किसी सहेजे गए template से या किसी draftId से आती है।

हर भेजने वाली कॉल एक आइडेम्पोटेंसी कुंजी रखती है। क्लाइंट हर कॉल के लिए एक बनाता है और रीट्राई में उसी को दोबारा इस्तेमाल करता है, इसलिए दोबारा आज़माया गया अनुरोध पहला संदेश दोहराता है। इसे प्रोसेस और रीस्टार्ट के पार भी बनाए रखने के लिए openemail.WithIdempotencyKey पास करें।

Attachments

attachments.go
invoice, err := os.ReadFile("invoice.pdf")if err != nil {	return err} _, err = client.Emails.Send(ctx, openemail.Body{	"from":    "[email protected]",	"to":      "[email protected]",	"subject": "Your September invoice",	"text":    "The invoice is attached.",	"attachments": []openemail.Body{		{"filename": "invoice.pdf", "content": invoice, "contentType": "application/pdf"},		{"fileId": "file_3f9c2a7b1e4d8f60a5c7b92d"},	},}) return err

content एक []byte या एक io.Reader लेता है, जिसे क्लाइंट base64 में एनकोड करता है, या ऐसा टेक्स्ट जो पहले से base64 है। fileId उस फ़ाइल का नाम देता है जो client.Files.Upload से अपलोड की गई है, और 5 MB से बड़ी फ़ाइल इसी तरह भेजी जाती है।

बाद में भेजें

schedule.go
scheduled, err := client.Emails.Send(ctx, openemail.Body{	"from":        "[email protected]",	"to":          "[email protected]",	"subject":     "Your invoice is due tomorrow",	"text":        "A reminder that the invoice is due tomorrow.",	"scheduledAt": time.Now().Add(24 * time.Hour),})if err != nil {	return err} if _, err := client.Emails.Reschedule(ctx, scheduled.ID(), time.Now().Add(48*time.Hour)); err != nil {	return err} cancelled, err := client.Emails.Cancel(ctx, scheduled.ID())if err != nil {	return err} fmt.Println(cancelled.String("status"))

scheduledAt एक time.Time, एक ISO 8601 क्षण या PT1H जैसी अवधि लेता है। बॉडी में कहीं भी मौजूद time.Time को UTC में ISO 8601 क्षण के रूप में भेजा जाता है। शेड्यूल किया गया संदेश जाने तक बदला या रद्द किया जा सकता है।

batch भेजें

batch.go
result, err := client.Emails.SendBatch(ctx, []openemail.Body{	{"from": "[email protected]", "to": "[email protected]", "subject": "Order AC-4192 has shipped", "text": "It is on its way."},	{"from": "[email protected]", "to": "[email protected]", "subject": "Order AC-4193 has shipped", "text": "It is on its way."},})if err != nil {	return err} fmt.Println(result.Sent, "sent,", result.Failed, "failed") for _, item := range result.Items {	if item.String("status") == "error" {		fmt.Println(item.Int("index"), item.Object("error").String("message"))	}}

एक बैच में 100 तक संदेश आ सकते हैं और यह कभी सब या कुछ नहीं वाला नहीं होता: गलत पता सिर्फ़ अपने आइटम को विफल करता है और बाकी फिर भी चले जाते हैं। एरर पर निर्भर रहने के बजाय Failed और हर आइटम का status जाँचें।