Skip to main content
The Resend Go SDK supports adding file attachments to emails, either from local content or remote URLs, including inline attachments for embedding images in HTML.

Quick Start

Here’s how to send an email with attachments:

Attachment Struct

The Attachment struct supports the following fields:
[]byte
Binary content of the attachment. Use when providing file content directly instead of a remote path.
string
required
Filename that will appear in the email. Choose the correct extension for proper preview behavior.
string
URL where the attachment file is hosted. Use instead of providing Content directly.
string
MIME type for the attachment (e.g., application/pdf, image/png). If not set, it will be derived from the Filename.
string
Optional content ID for inline attachments. Set this to reference the attachment in HTML using cid: prefix. Makes the attachment inline.
You must provide either Content or Path, but not both.
Source: emails.go:117

Adding Attachments from Local Files

Read a file from disk and attach it to an email:
Source: examples/with_attachments.go:20

Adding Attachments from Remote URLs

You can attach files hosted at remote URLs without downloading them first:
Source: examples/with_attachments.go:35
Using remote URLs via Path is more efficient for large files since the SDK doesn’t need to load them into memory.

Multiple Attachments

You can attach multiple files to a single email:
Source: examples/with_attachments.go:29

Inline Attachments

Inline attachments allow you to embed images directly in your HTML content using the cid: (Content-ID) reference.

Basic Inline Attachment

Source: examples/with_inline_attachments.go:22

How Inline Attachments Work

1

Set ContentId

Assign a unique ContentId to your attachment:
2

Reference in HTML

Use the cid: prefix in your HTML src attribute:
3

Send Email

The image will be embedded directly in the email:

Multiple Inline Images

Each inline attachment must have a unique ContentId within the same email.

Content Types

Common MIME types for attachments:
If ContentType is not specified, Resend will attempt to derive it from the Filename extension.

Retrieving Attachments

You can retrieve attachment information for sent emails:

List All Attachments

Source: examples/with_attachments.go:56

List with Pagination

Source: examples/with_attachments.go:74

Get Specific Attachment

Source: examples/with_attachments.go:86

EmailAttachment Response

The EmailAttachment struct returned from retrieval methods includes:
string
Unique identifier for the attachment.
string
Name of the attached file.
string
MIME type of the attachment.
string
Content disposition (e.g., attachment or inline).
string
Content ID if this was an inline attachment.
string
Temporary URL to download the attachment.
string
ISO 8601 timestamp when the download URL expires.
Source: emails.go:96

Common Use Cases

Best Practices

1

Specify Content Types

Always specify ContentType for better email client compatibility:
2

Use Descriptive Filenames

Choose clear, descriptive filenames with proper extensions:
3

Optimize File Sizes

Keep attachments reasonably sized. Compress large files before attaching:
4

Use Remote URLs for Large Files

For large files, use Path instead of Content to avoid memory issues:
5

Unique ContentIds for Inline

Use unique, descriptive ContentId values for inline attachments:

Size Limits

Attachment Size Limits:
  • Maximum total attachment size per email: 25 MB
  • Individual attachment size: No specific limit, but keep under 25 MB total
  • Consider using cloud storage links for files larger than 10 MB

Next Steps

Sending Emails

Learn the basics of sending emails

Email Templates

Use templates with attachments

Batch Emails

Send emails with attachments in bulk

Scheduled Emails

Schedule emails with attachments