- 
                Notifications
    
You must be signed in to change notification settings  - Fork 9
 
feat: Inbound API #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    feat: Inbound API #134
Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      8965a0f
              
                feat: inbound attachment methods
              
              
                drish 8885dfe
              
                lint: fix
              
              
                drish 127cdef
              
                Update examples/receiving_emails.rb
              
              
                drish f2b1d7b
              
                Update examples/receiving_emails.rb
              
              
                drish a12ca47
              
                Update examples/receiving_emails.rb
              
              
                drish 1bba55a
              
                merge main
              
              
                drish d74969f
              
                Merge branch 'feat/inbound' of https://github.com/resendlabs/resend-r…
              
              
                drish File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # frozen_string_literal: true | ||
| 
     | 
||
| require_relative "../lib/resend" | ||
| 
     | 
||
| raise if ENV["RESEND_API_KEY"].nil? | ||
| 
     | 
||
| Resend.api_key = ENV["RESEND_API_KEY"] | ||
| 
     | 
||
| puts "=== Listing Received Emails ===" | ||
| 
     | 
||
| # List all received emails with default settings | ||
| puts "\nListing all received emails:" | ||
| emails = Resend::Emails::Receiving.list | ||
| 
     | 
||
| puts "Total emails in response: #{emails[:data].length}" | ||
| puts "Has more: #{emails[:has_more]}" | ||
| 
     | 
||
| emails[:data].each do |e| | ||
| puts " - #{e["id"]}: #{e["subject"]} from #{e["from"]}" | ||
| puts " Created: #{e["created_at"]}" | ||
| if e["attachments"] && !e["attachments"].empty? | ||
| puts " Attachments: #{e["attachments"].length}" | ||
| end | ||
| end | ||
| 
     | 
||
| # List with custom limit | ||
                
      
                  drish marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| puts "\n\nListing with limit of 5:" | ||
| limited_emails = Resend::Emails::Receiving.list(limit: 5) | ||
| 
     | 
||
| puts "Retrieved #{limited_emails[:data].length} emails" | ||
| puts "Has more: #{limited_emails[:has_more]}" | ||
| 
     | 
||
| # Example of pagination (if you have more emails) | ||
| if limited_emails[:has_more] && limited_emails[:data].last | ||
| last_id = limited_emails[:data].last["id"] | ||
| puts "\n\nGetting next page after ID: #{last_id}" | ||
| next_page = Resend::Emails::Receiving.list(limit: 5, after: last_id) | ||
| puts "Next page has #{next_page[:data].length} emails" | ||
| end | ||
| 
     | 
||
| puts "\n\n=== Retrieving Single Received Email ===" | ||
| 
     | 
||
| # Use the first email from the list, or specify a known ID | ||
| if emails[:data] && emails[:data].first | ||
| email_id = emails[:data].first["id"] | ||
| else | ||
| # Replace with an actual received email ID from your account | ||
| email_id = "006e2796-ff6a-4436-91ad-0429e600bf8a" | ||
| end | ||
| 
     | 
||
| email = Resend::Emails::Receiving.get(email_id) | ||
| 
     | 
||
| puts "\nEmail Details:" | ||
| puts " ID: #{email[:id]}" | ||
| puts " From: #{email[:from]}" | ||
| puts " To: #{email[:to].join(', ')}" | ||
| puts " Subject: #{email[:subject]}" | ||
| puts " Created At: #{email[:created_at]}" | ||
| puts " Message ID: #{email[:message_id]}" | ||
| 
     | 
||
| if email[:cc] && !email[:cc].empty? | ||
| puts " CC: #{email[:cc].join(', ')}" | ||
| end | ||
| 
     | 
||
| if email[:bcc] && !email[:bcc].empty? | ||
| puts " BCC: #{email[:bcc].join(', ')}" | ||
| end | ||
| 
     | 
||
| if email[:attachments] && !email[:attachments].empty? | ||
| puts "\n Attachments:" | ||
| email[:attachments].each do |attachment| | ||
| puts " - #{attachment["filename"]} (#{attachment["content_type"]})" | ||
| puts " ID: #{attachment["id"]}" | ||
| puts " Size: #{attachment["size"]} bytes" if attachment["size"] | ||
| puts " Content ID: #{attachment["content_id"]}" if attachment["content_id"] | ||
| end | ||
| 
     | 
||
| # List all attachments for this email | ||
                
      
                  drish marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| puts "\n Listing all attachments for email: #{email[:id]}" | ||
| attachments_list = Resend::Attachments::Receiving.list( | ||
| email_id: email[:id] | ||
| ) | ||
| 
     | 
||
| puts " Total attachments: #{attachments_list[:data].length}" | ||
| puts " Has more: #{attachments_list[:has_more]}" | ||
| 
     | 
||
| # Retrieve full attachment details for the first attachment | ||
| if email[:attachments].first | ||
| first_attachment_id = email[:attachments].first["id"] | ||
| puts "\n Retrieving full attachment details for: #{first_attachment_id}" | ||
| 
     | 
||
| attachment_details = Resend::Attachments::Receiving.get( | ||
| id: first_attachment_id, | ||
| email_id: email[:id] | ||
| ) | ||
| 
     | 
||
| puts " Download URL: #{attachment_details[:download_url]}" | ||
| puts " Expires At: #{attachment_details[:expires_at]}" | ||
| end | ||
| end | ||
| 
     | 
||
| puts "\n HTML Content:" | ||
| puts " #{email[:html][0..100]}..." if email[:html] | ||
| 
     | 
||
| puts "\n Text Content:" | ||
| puts " #{email[:text]}" if email[:text] | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # frozen_string_literal: true | ||
| 
     | 
||
| module Resend | ||
| module Attachments | ||
| module Receiving | ||
| class << self | ||
| # Retrieve a single attachment from a received email | ||
| # | ||
| # @param params [Hash] Parameters for retrieving the attachment | ||
| # @option params [String] :id The attachment ID (required) | ||
| # @option params [String] :email_id The email ID (required) | ||
| # @return [Hash] The attachment object | ||
| # | ||
| # @example | ||
| # Resend::Attachments::Receiving.get( | ||
| # id: "2a0c9ce0-3112-4728-976e-47ddcd16a318", | ||
| # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" | ||
| # ) | ||
| def get(params = {}) | ||
| attachment_id = params[:id] | ||
| email_id = params[:email_id] | ||
| 
     | 
||
| path = "emails/receiving/#{email_id}/attachments/#{attachment_id}" | ||
| Resend::Request.new(path, {}, "get").perform | ||
| end | ||
| 
     | 
||
| # List attachments from a received email with optional pagination | ||
| # | ||
| # @param params [Hash] Parameters for listing attachments | ||
| # @option params [String] :email_id The email ID (required) | ||
| # @option params [Integer] :limit Maximum number of attachments to return (1-100) | ||
| # @option params [String] :after Cursor for pagination (newer attachments) | ||
| # @option params [String] :before Cursor for pagination (older attachments) | ||
| # @return [Hash] List of attachments with pagination info | ||
| # | ||
| # @example List all attachments | ||
| # Resend::Attachments::Receiving.list( | ||
| # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" | ||
| # ) | ||
| # | ||
| # @example List with custom limit | ||
| # Resend::Attachments::Receiving.list( | ||
| # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c", | ||
| # limit: 50 | ||
| # ) | ||
| # | ||
| # @example List with pagination | ||
| # Resend::Attachments::Receiving.list( | ||
| # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c", | ||
| # limit: 20, | ||
| # after: "attachment_id_123" | ||
| # ) | ||
| def list(params = {}) | ||
| email_id = params[:email_id] | ||
| path = "emails/receiving/#{email_id}/attachments" | ||
| 
     | 
||
| # Build query parameters, filtering out nil values | ||
| query_params = {} | ||
| query_params[:limit] = params[:limit] if params[:limit] | ||
| query_params[:after] = params[:after] if params[:after] | ||
| query_params[:before] = params[:before] if params[:before] | ||
| 
     | 
||
| Resend::Request.new(path, query_params, "get").perform | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # frozen_string_literal: true | ||
| 
     | 
||
| module Resend | ||
| module Emails | ||
| module Receiving | ||
| class << self | ||
| # Retrieve a single received email | ||
| # | ||
| # @param email_id [String] The ID of the received email | ||
| # @return [Hash] The received email object | ||
| # | ||
| # @example | ||
| # Resend::Emails::Receiving.get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c") | ||
| def get(email_id = "") | ||
| path = "emails/receiving/#{email_id}" | ||
| Resend::Request.new(path, {}, "get").perform | ||
| end | ||
| 
     | 
||
| # List received emails with optional pagination | ||
| # | ||
| # @param params [Hash] Optional parameters for pagination | ||
| # @option params [Integer] :limit Maximum number of emails to return (1-100) | ||
| # @option params [String] :after Cursor for pagination (newer emails) | ||
| # @option params [String] :before Cursor for pagination (older emails) | ||
| # @return [Hash] List of received emails with pagination info | ||
| # | ||
| # @example List all received emails | ||
| # Resend::Emails::Receiving.list | ||
| # | ||
| # @example List with custom limit | ||
| # Resend::Emails::Receiving.list(limit: 50) | ||
| # | ||
| # @example List with pagination | ||
| # Resend::Emails::Receiving.list(limit: 20, after: "email_id_123") | ||
| def list(params = {}) | ||
| path = Resend::PaginationHelper.build_paginated_path("emails/receiving", params) | ||
| Resend::Request.new(path, {}, "get").perform | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.