Quick Start
Here’s how to send an email with attachments:Attachment Struct
TheAttachment 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.Adding Attachments from Local Files
Read a file from disk and attach it to an email:Adding Attachments from Remote URLs
You can attach files hosted at remote URLs without downloading them first:Multiple Attachments
You can attach multiple files to a single email:Inline Attachments
Inline attachments allow you to embed images directly in your HTML content using thecid: (Content-ID) reference.
Basic Inline Attachment
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
Content Types
Common MIME types for attachments:- Documents
- Images
- Archives
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
List with Pagination
Get Specific Attachment
EmailAttachment Response
TheEmailAttachment 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.
Common Use Cases
Invoice Emails
Invoice Emails
Report with Multiple Files
Report with Multiple Files
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
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