Module: Resend::Emails

Included in:
Client
Defined in:
lib/resend/emails.rb,
lib/resend/emails/receiving.rb,
lib/resend/emails/attachments.rb,
lib/resend/emails/receiving/attachments.rb

Overview

Module responsible for wrapping email sending API

Defined Under Namespace

Modules: Attachments, Receiving

Class Method Summary collapse

Class Method Details

.cancel(email_id = "") ⇒ Object

Cancel a scheduled email. see more: https://resend.com/docs/api-reference/emails/cancel-email



30
31
32
33
# File 'lib/resend/emails.rb', line 30

def cancel(email_id = "")
  path = "emails/#{email_id}/cancel"
  Resend::Request.new(path, {}, "post").perform
end

.get(email_id = "") ⇒ Object



16
17
18
19
# File 'lib/resend/emails.rb', line 16

def get(email_id = "")
  path = "emails/#{email_id}"
  Resend::Request.new(path, {}, "get").perform
end

.list(options = {}) ⇒ Object

List emails with optional pagination. see more: https://resend.com/docs/api-reference/emails/list-emails

Parameters:

  • options (Hash) (defaults to: {})

    Optional parameters for pagination

Options Hash (options):

  • :limit (Integer)

    Maximum number of emails to return (1-100, default 20)

  • :after (String)

    Cursor for pagination (newer emails)

  • :before (String)

    Cursor for pagination (older emails)



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/resend/emails.rb', line 53

def list(options = {})
  path = "emails"

  # Build query parameters, filtering out nil values
  query_params = {}
  query_params[:limit] = options[:limit] if options[:limit]
  query_params[:after] = options[:after] if options[:after]
  query_params[:before] = options[:before] if options[:before]

  Resend::Request.new(path, query_params, "get").perform
end

.metrics(options = {}) ⇒ Object

Retrieve email metrics. see more: https://resend.com/docs/api-reference/emails/metrics

Parameters:

  • options (Hash) (defaults to: {})

    Optional parameters for filtering and shaping the metrics response

Options Hash (options):

  • :start_date (String)

    ISO 8601 date/datetime. Defaults to 6 days before :end_date

  • :end_date (String)

    ISO 8601 date/datetime. Defaults to now

  • :timezone (String)

    IANA timezone, e.g. "America/New_York". Defaults to "UTC"

  • :granularity (String)

    Bucket size used when :period is in :dimensions. One of "hourly", "daily", "weekly", "monthly". Defaults to "daily"

  • :metrics (Array<String>)

    Metrics to include. Defaults to all metrics.

  • :dimensions (Array<String>)

    Dimensions to break down by: "period", "domain", "email", "broadcast". Defaults to none, which returns totals only.

  • :domain_id (Array<String>)

    Restrict to these sending domain IDs (max 100)

  • :email_id (Array<String>)

    Restrict to these email IDs (max 100)

  • :broadcast_id (Array<String>)

    Restrict to these broadcast IDs (max 100)



80
81
82
83
84
# File 'lib/resend/emails.rb', line 80

def metrics(options = {})
  path = "emails/metrics"
  validate_metrics_options(options)
  Resend::Request.new(path, build_metrics_query(options), "get").perform
end

.send(params, options: {}) ⇒ Object

Sends or schedules an email. see more: https://resend.com/docs/api-reference/emails/send-email



9
10
11
12
# File 'lib/resend/emails.rb', line 9

def send(params, options: {})
  path = "emails"
  Resend::Request.new(path, params, "post", options: options).perform
end

.share(email_id, params = {}) ⇒ Object

Create a shareable link for a sent or received email.

Parameters:

  • email_id (String)

    The email id (sent or received).

  • params (Hash) (defaults to: {})

    Optional parameters

Options Hash (params):

  • :expires_in (String)

    Human-readable duration (e.g. "10m", "2 hours", "1 day"). Defaults to "48h" and is capped at 48 hours.



41
42
43
44
# File 'lib/resend/emails.rb', line 41

def share(email_id, params = {})
  path = "emails/#{email_id}/share"
  Resend::Request.new(path, params, "post").perform
end

.update(params) ⇒ Object

Update a scheduled email. see more: https://resend.com/docs/api-reference/emails/update-email



23
24
25
26
# File 'lib/resend/emails.rb', line 23

def update(params)
  path = "emails/#{params[:email_id]}"
  Resend::Request.new(path, params, "patch").perform
end