Skip to main content

GetAttachment

Retrieves a single attachment from a sent email.
func (s *EmailsSvcImpl) GetAttachment(emailId string, attachmentId string) (*EmailAttachment, error)

Parameters

emailId
string
required
The unique identifier of the email.
attachmentId
string
required
The unique identifier of the attachment.

Returns

response
*EmailAttachment

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

ctx
context.Context
required
Context for the request.
emailId
string
required
The unique identifier of the email.
attachmentId
string
required
The unique identifier of the attachment.

Returns

response
*EmailAttachment
See GetAttachment for response field details.

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

emailId
string
required
The unique identifier of the email.

Returns

response
ListEmailAttachmentsResponse

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

ctx
context.Context
required
Context for the request.
emailId
string
required
The unique identifier of the email.

Returns

response
ListEmailAttachmentsResponse
See ListAttachments for response field details.

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

ctx
context.Context
required
Context for the request.
emailId
string
required
The unique identifier of the email.
options
*ListOptions
Pagination options for the list request.

Returns

response
ListEmailAttachmentsResponse
See ListAttachments for response field details.

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)
}

Build docs developers (and LLMs) love