GetAttachment
Retrieves a single attachment from a sent email.
func (s *EmailsSvcImpl) GetAttachment(emailId string, attachmentId string) (*EmailAttachment, error)
Parameters
The unique identifier of the email.
The unique identifier of the attachment.
Returns
Show EmailAttachment fields
The object type (“attachment”). Only included when retrieving a single attachment.
The unique identifier of the attachment.
The filename of the attachment.
The MIME type of the attachment (e.g., “application/pdf”).
How the attachment should be displayed (“attachment” or “inline”).
Content ID for inline attachments. Used with cid: prefix in HTML.
Temporary URL to download the attachment.
Timestamp when the download URL expires.
Example
package main
import (
"fmt"
"github.com/resend/resend-go/v3"
)
func main() {
client := resend.NewClient("re_123456789")
attachment, err := client.Emails.GetAttachment(
"4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
"dh3m14y0-njhb-4079-a1c2-1ec49a5bc857",
)
if err != nil {
panic(err)
}
fmt.Printf("Attachment: %s (%s)\n", attachment.Filename, attachment.ContentType)
fmt.Printf("Download URL: %s\n", attachment.DownloadUrl)
fmt.Printf("Expires At: %s\n", attachment.ExpiresAt)
}
GetAttachmentWithContext
Retrieves a single attachment from a sent email with context.
func (s *EmailsSvcImpl) GetAttachmentWithContext(ctx context.Context, emailId string, attachmentId string) (*EmailAttachment, error)
Parameters
The unique identifier of the email.
The unique identifier of the attachment.
Returns
Example
package main
import (
"context"
"fmt"
"github.com/resend/resend-go/v3"
)
func main() {
ctx := context.Background()
client := resend.NewClient("re_123456789")
attachment, err := client.Emails.GetAttachmentWithContext(
ctx,
"4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
"dh3m14y0-njhb-4079-a1c2-1ec49a5bc857",
)
if err != nil {
panic(err)
}
fmt.Printf("Attachment: %s\n", attachment.Filename)
}
ListAttachments
Retrieves a list of attachments for a sent email.
func (s *EmailsSvcImpl) ListAttachments(emailId string) (ListEmailAttachmentsResponse, error)
Parameters
The unique identifier of the email.
Returns
response
ListEmailAttachmentsResponse
Show ListEmailAttachmentsResponse fields
The object type (“list”).
Indicates whether there are more attachments available beyond this page.
Array of attachment objects. See GetAttachment for EmailAttachment field details. Note: The Object field is omitted in list responses.
Example
package main
import (
"fmt"
"github.com/resend/resend-go/v3"
)
func main() {
client := resend.NewClient("re_123456789")
attachments, err := client.Emails.ListAttachments("4ef9a417-02e9-4d39-ad75-9611e0fcc33c")
if err != nil {
panic(err)
}
fmt.Printf("Found %d attachments\n", len(attachments.Data))
for _, att := range attachments.Data {
fmt.Printf("- ID: %s, Filename: %s, ContentType: %s\n",
att.Id, att.Filename, att.ContentType)
}
}
ListAttachmentsWithContext
Retrieves a list of attachments for a sent email with context.
func (s *EmailsSvcImpl) ListAttachmentsWithContext(ctx context.Context, emailId string) (ListEmailAttachmentsResponse, error)
Parameters
The unique identifier of the email.
Returns
response
ListEmailAttachmentsResponse
Example
package main
import (
"context"
"fmt"
"github.com/resend/resend-go/v3"
)
func main() {
ctx := context.Background()
client := resend.NewClient("re_123456789")
attachments, err := client.Emails.ListAttachmentsWithContext(
ctx,
"4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
)
if err != nil {
panic(err)
}
fmt.Printf("Found %d attachments\n", len(attachments.Data))
}
ListAttachmentsWithOptions
Retrieves a list of attachments for a sent email with pagination options.
func (s *EmailsSvcImpl) ListAttachmentsWithOptions(ctx context.Context, emailId string, options *ListOptions) (ListEmailAttachmentsResponse, error)
Parameters
The unique identifier of the email.
Pagination options for the list request.
Maximum number of attachments to return. Must be a pointer to an integer.
Cursor for forward pagination. Returns attachments after this attachment ID. Must be a pointer to a string.
Cursor for backward pagination. Returns attachments before this attachment ID. Must be a pointer to a string.
Returns
response
ListEmailAttachmentsResponse
Example
package main
import (
"context"
"fmt"
"github.com/resend/resend-go/v3"
)
func main() {
ctx := context.Background()
client := resend.NewClient("re_123456789")
limit := 10
listOptions := &resend.ListOptions{
Limit: &limit,
}
attachments, err := client.Emails.ListAttachmentsWithOptions(
ctx,
"4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
listOptions,
)
if err != nil {
panic(err)
}
fmt.Printf("Found %d attachments (limit: %d)\n", len(attachments.Data), limit)
fmt.Printf("Has more: %v\n", attachments.HasMore)
}