Prerequisites
Before you begin, make sure you have:- Go 1.23 or later installed
- The Resend Go SDK installed (see Installation)
- A Resend API key (get one from the Resend Dashboard)
Send your first email
Get your API key
Sign in to your Resend account and navigate to the API Keys page. Create a new API key or copy an existing one.Store your API key in an environment variable:
Create a new Go file
Create a new file called
main.go with the following code:The example uses
[email protected] as the recipient, which is a test email that Resend provides. Replace it with your actual recipient email address.Run your code
Execute your program:You should see output similar to:The returned ID is your email’s unique identifier that you can use to track delivery status.
Verify email delivery
Check the recipient’s inbox to confirm the email was delivered. You can also view the email in your Resend Dashboard.
Send HTML emails
Enhance your emails with HTML content:You can specify both
Html and Text fields. The Text field serves as a fallback for email clients that don’t support HTML.Use idempotency keys
Prevent duplicate emails by using idempotency keys. This is useful when you want to ensure an email is only sent once, even if your code retries the request:Send with attachments
Attach files to your emails using either local file content or remote URLs:Send batch emails
Send multiple emails in a single API call for better performance:Batch sending supports both strict validation (default) where all emails must be valid, or permissive mode where valid emails are sent even if some fail validation.
Common errors and solutions
Authentication failed
Authentication failed
Error:
401 UnauthorizedSolution: Verify that your API key is correct and properly set in the environment variable. Make sure you’re using a valid API key from your Resend Dashboard.Invalid from address
Invalid from address
Error:
422 Unprocessable Entity - Invalid from addressSolution: The From field must use a domain you’ve verified in Resend. You can use [email protected] for testing, or add and verify your own domain in the Domains section.Rate limit exceeded
Rate limit exceeded
Error:
429 Too Many RequestsSolution: You’ve exceeded your rate limit. The SDK provides rate limit information in the error response. Wait for the specified retry-after period before sending more emails, or upgrade your plan for higher limits.Context timeout
Context timeout
Error:
context deadline exceededSolution: The request took too long to complete. The default HTTP client has a 1-minute timeout. You can create a custom HTTP client with a longer timeout if needed, or check your network connection.Next steps
Now that you’ve sent your first email, explore more advanced features:Email templates
Create reusable email templates with variables
Schedule emails
Schedule emails for future delivery
Webhooks
Receive real-time email event notifications
Manage contacts
Organize contacts into audiences and segments