Class: Sendpost::EmailApi
- Inherits:
-
Object
- Object
- Sendpost::EmailApi
- Defined in:
- lib/sendpost_ruby_sdk/api/email_api.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
Instance Method Summary collapse
-
#initialize(api_client = ApiClient.default) ⇒ EmailApi
constructor
A new instance of EmailApi.
-
#send_email(email_message_object, opts = {}) ⇒ Array<EmailResponse>
Send Email Send transactional or marketing emails to one or multiple recipients.
-
#send_email_with_http_info(email_message_object, opts = {}) ⇒ Array<(Array<EmailResponse>, Integer, Hash)>
Send Email Send transactional or marketing emails to one or multiple recipients.
-
#send_email_with_template(email_message_with_template, opts = {}) ⇒ Array<EmailResponse>
Send Email With Template Send emails using pre-configured templates stored in SendPost.
-
#send_email_with_template_with_http_info(email_message_with_template, opts = {}) ⇒ Array<(Array<EmailResponse>, Integer, Hash)>
Send Email With Template Send emails using pre-configured templates stored in SendPost.
Constructor Details
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
17 18 19 |
# File 'lib/sendpost_ruby_sdk/api/email_api.rb', line 17 def api_client @api_client end |
Instance Method Details
#send_email(email_message_object, opts = {}) ⇒ Array<EmailResponse>
Send Email
Send transactional or marketing emails to one or multiple recipients. This is the primary endpoint for all email sending through SendPost. Capabilities: - Single Email: Send to one recipient with full personalization - Batch Sending: Send to up to 500 recipients in a single API call - Personalization: Use Handlebars templating ({{variableName}}) in subject, HTML body, and text body - Attachments: Include base64-encoded files (max 25MB total per request) - Tracking: Enable/disable open and click tracking per email - IP Pool Routing: Route emails through specific IP pools Common Use Cases: | Use Case | Example | |----------|---------| | Order Confirmation | Send receipt with order details after purchase | | Password Reset | Time-sensitive security email with reset link | | Welcome Email | Onboard new users with personalized greeting | | Shipping Notification | Update customers when orders ship | | Invoice/Receipt | Attach PDF invoices to billing emails | Personalization Example: json { \"to\": [{ \"email\": \"[email protected]\", \"customFields\": { \"firstName\": \"John\", \"orderTotal\": \"$99.99\" } }], \"subject\": \"Hi {{firstName}}, your order is confirmed!\", \"htmlBody\": \"<p>Thanks {{firstName}}! Your total: {{orderTotal}}</p>\" } Test Email Addresses: SendPost provides special test email addresses for testing webhooks and events without sending real emails: | Test Email | Behavior | |------------|----------| | [email protected] | Generates delivered event, then simulates opens and clicks after a few seconds | | [email protected] | Generates delivered event only (no opens/clicks) | | [email protected] | Always generates a hard bounce event | | [email protected] | Always generates a soft bounce event | | [email protected] | Always generates a dropped event (SMTPDropped) | Self-Test Email (Send to Yourself): Use [email protected] as the from address to send emails to yourself for testing: - Sender: Must be [email protected] - Recipient: Must be your account owner email (the email you used to sign up) - Behavior: Real email delivery to your inbox (no domain verification required, no mock mode) - Use Case: Test your API integration by sending real emails to yourself without domain setup Example: json { \"from\": {\"email\": \"[email protected]\"}, \"to\": [{\"email\": \"[email protected]\"}], \"subject\": \"Test Email to Myself\", \"htmlBody\": \"<p>This is a test email to myself</p>\" } This will send a real email to your inbox that you can actually receive and open. Note: If you send to any email other than your account email, the request will be rejected with an error. Using Test Emails: - Simply send to any test email address like a normal recipient - Mock mode is automatically enabled for test emails - All events trigger webhooks normally - Events are marked as mock messages but follow the same structure as real events - Perfect for testing webhook integrations without using real email addresses Example: json { \"to\": [{\"email\": \"[email protected]\"}], \"from\": {\"email\": \"[email protected]\"}, \"subject\": \"Test Email\", \"htmlBody\": \"<p>This is a test</p>\" } This will generate: Sent → Delivered → Opened (after 2-5s) → Clicked (after 1-3s more) Response: Returns an array of responses, one per recipient, each containing: - messageId - Unique ID for tracking - submittedAt - Timestamp of acceptance - errorCode and message - Status information
27 28 29 30 |
# File 'lib/sendpost_ruby_sdk/api/email_api.rb', line 27 def send_email(, opts = {}) data, _status_code, _headers = send_email_with_http_info(, opts) data end |
#send_email_with_http_info(email_message_object, opts = {}) ⇒ Array<(Array<EmailResponse>, Integer, Hash)>
Send Email Send transactional or marketing emails to one or multiple recipients. This is the primary endpoint for all email sending through SendPost. Capabilities: - Single Email: Send to one recipient with full personalization - Batch Sending: Send to up to 500 recipients in a single API call - Personalization: Use Handlebars templating (`{variableName}`) in subject, HTML body, and text body - Attachments: Include base64-encoded files (max 25MB total per request) - Tracking: Enable/disable open and click tracking per email - IP Pool Routing: Route emails through specific IP pools Common Use Cases: | Use Case | Example | |----------|---------| | Order Confirmation | Send receipt with order details after purchase | | Password Reset | Time-sensitive security email with reset link | | Welcome Email | Onboard new users with personalized greeting | | Shipping Notification | Update customers when orders ship | | Invoice/Receipt | Attach PDF invoices to billing emails | Personalization Example: ```json { "to": [{ "email": "[email protected]", "customFields": { "firstName": "John", "orderTotal": "$99.99" } }], "subject": "Hi {firstName}, your order is confirmed!", "htmlBody": "<p>Thanks {firstName}! Your total: {orderTotal}</p>" } ``` Test Email Addresses: SendPost provides special test email addresses for testing webhooks and events without sending real emails: | Test Email | Behavior | |------------|----------| | `[email protected]` | Generates delivered event, then simulates opens and clicks after a few seconds | | `[email protected]` | Generates delivered event only (no opens/clicks) | | `[email protected]` | Always generates a hard bounce event | | `[email protected]` | Always generates a soft bounce event | | `[email protected]` | Always generates a dropped event (SMTPDropped) | Self-Test Email (Send to Yourself): Use `[email protected]` as the from address to send emails to yourself for testing: - Sender: Must be `[email protected]` - Recipient: Must be your account owner email (the email you used to sign up) - Behavior: Real email delivery to your inbox (no domain verification required, no mock mode) - Use Case: Test your API integration by sending real emails to yourself without domain setup Example: ```json { "from": \"[email protected]\", "to": [\"[email protected]\"], "subject": "Test Email to Myself", "htmlBody": "<p>This is a test email to myself</p>" } ``` This will send a real email to your inbox that you can actually receive and open. Note: If you send to any email other than your account email, the request will be rejected with an error. Using Test Emails: - Simply send to any test email address like a normal recipient - Mock mode is automatically enabled for test emails - All events trigger webhooks normally - Events are marked as mock messages but follow the same structure as real events - Perfect for testing webhook integrations without using real email addresses Example: ```json { "to": [\"[email protected]\"], "from": \"[email protected]\", "subject": "Test Email", "htmlBody": "<p>This is a test</p>" } ``` This will generate: Sent → Delivered → Opened (after 2-5s) → Clicked (after 1-3s more) Response: Returns an array of responses, one per recipient, each containing: - `messageId` - Unique ID for tracking - `submittedAt` - Timestamp of acceptance - `errorCode` and `message` - Status information
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sendpost_ruby_sdk/api/email_api.rb', line 37 def send_email_with_http_info(, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: EmailApi.send_email ...' end # verify the required parameter 'email_message_object' is set if @api_client.config.client_side_validation && .nil? fail ArgumentError, "Missing the required parameter 'email_message_object' when calling EmailApi.send_email" end # resource path local_var_path = '/subaccount/email/' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type(['application/json']) if !content_type.nil? header_params['Content-Type'] = content_type end # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] || @api_client.object_to_http_body() # return_type return_type = opts[:debug_return_type] || 'Array<EmailResponse>' # auth_names auth_names = opts[:debug_auth_names] || ['subAccountAuth'] = opts.merge( :operation => :"EmailApi.send_email", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:POST, local_var_path, ) if @api_client.config.debugging @api_client.config.logger.debug "API called: EmailApi#send_email\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |
#send_email_with_template(email_message_with_template, opts = {}) ⇒ Array<EmailResponse>
Send Email With Template
Send emails using pre-configured templates stored in SendPost. Templates separate email content from code, enabling: Benefits: - Update email content without code deployments - Marketing teams can manage templates independently - Consistent branding across all applications - A/B test different template versions How It Works: 1. Create templates in the SendPost dashboard with Handlebars variables 2. Reference the template by name or ID in this API call 3. Pass dynamic data through recipient customFields 4. SendPost merges data with template and sends Common Use Cases: | Template Type | Dynamic Data | |---------------|--------------| | Welcome Email | firstName, accountType, loginUrl | | Order Receipt | orderNumber, items, total, shippingAddress | | Password Reset | resetLink, expiryTime, userName | | Weekly Digest | articleList, unreadCount, userName | Example Request: json { \"from\": { \"email\": \"[email protected]\" }, \"to\": [{ \"email\": \"[email protected]\", \"customFields\": { \"firstName\": \"Sarah\", \"orderNumber\": \"ORD-2024-001\", \"totalAmount\": \"$149.99\" } }], \"template\": \"order-confirmation-v2\" } Note: Template variables not provided in customFields will render as empty strings.
95 96 97 98 |
# File 'lib/sendpost_ruby_sdk/api/email_api.rb', line 95 def send_email_with_template(, opts = {}) data, _status_code, _headers = send_email_with_template_with_http_info(, opts) data end |
#send_email_with_template_with_http_info(email_message_with_template, opts = {}) ⇒ Array<(Array<EmailResponse>, Integer, Hash)>
Send Email With Template Send emails using pre-configured templates stored in SendPost. Templates separate email content from code, enabling: Benefits: - Update email content without code deployments - Marketing teams can manage templates independently - Consistent branding across all applications - A/B test different template versions How It Works: 1. Create templates in the SendPost dashboard with Handlebars variables 2. Reference the template by name or ID in this API call 3. Pass dynamic data through recipient `customFields` 4. SendPost merges data with template and sends Common Use Cases: | Template Type | Dynamic Data | |---------------|--------------| | Welcome Email | `firstName`, `accountType`, `loginUrl` | | Order Receipt | `orderNumber`, `items`, `total`, `shippingAddress` | | Password Reset | `resetLink`, `expiryTime`, `userName` | | Weekly Digest | `articleList`, `unreadCount`, `userName` | Example Request: ```json { "from": { "email": "[email protected]" }, "to": [{ "email": "[email protected]", "customFields": { "firstName": "Sarah", "orderNumber": "ORD-2024-001", "totalAmount": "$149.99" } }], "template": "order-confirmation-v2" } ``` Note: Template variables not provided in `customFields` will render as empty strings.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sendpost_ruby_sdk/api/email_api.rb', line 105 def send_email_with_template_with_http_info(, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: EmailApi.send_email_with_template ...' end # verify the required parameter 'email_message_with_template' is set if @api_client.config.client_side_validation && .nil? fail ArgumentError, "Missing the required parameter 'email_message_with_template' when calling EmailApi.send_email_with_template" end # resource path local_var_path = '/subaccount/email/template' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type(['application/json']) if !content_type.nil? header_params['Content-Type'] = content_type end # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] || @api_client.object_to_http_body() # return_type return_type = opts[:debug_return_type] || 'Array<EmailResponse>' # auth_names auth_names = opts[:debug_auth_names] || ['subAccountAuth'] = opts.merge( :operation => :"EmailApi.send_email_with_template", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:POST, local_var_path, ) if @api_client.config.debugging @api_client.config.logger.debug "API called: EmailApi#send_email_with_template\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |