-
Notifications
You must be signed in to change notification settings - Fork 70
Sending test
To send a simple email, all you need to do is create a Postmark API client and send a mail message.
For these API requests you will need to use a server API token. Once you obtain it, you will need to use server API client.
For quick testing purposes though, Postmark lets you send test emails that won’t actually get delivered to the recipient. This method is typically used to verify that your data is valid. You can do this by passing POSTMARK_API_TEST
as your server API token.
server_token = 'POSTMARK_API_TEST'
client = Postmark::ApiClient.new(server token, http_open_timeout: 15)
Once you set the test server token, you can send a test email message which will not be sent, but it will return a proper sending response, just like it would if the email was sent.
The only difference between the real sending response and the test response is the message in the response. It would say OK
in real response, and Test job accepted
in test response.
client.deliver(from: '[email protected]',
to: 'Leonard Hofstadter <[email protected]>',
subject: 'Re: Come on, Sheldon. It will be fun.',
text_body: 'That\'s what you said about the Green Lantern.')
# => {:to=>"Leonard Hofstadter <[email protected]>", :submitted_at=>"2020-02-10T11:51:52.098666-05:00", :message_id=>"252a11e9-06c4-42d8-a6f1-8b992504ba2e", :error_code=>0, :message=>"Test job accepted"}
For more detailed testing, we suggest integration testing article.
For additional information about the capabilities of the Postmark API, see Postmark Developers Documentation.
- Email sending
- Test email sending
- Bounces
- Templates
- Templates push
- Server
- Servers
- Message Streams
- Webhooks
- Messages
- Domains
- Sender Signatures
- Stats
- Trigger Tags
- Suppressions
- Data Removals
- Trigger Inbound Rules
- Parsing Inbound
- Using Postmark with Mail library
- Accessing Postmark Message ID
- Error Handling
- Integration Testing
- Troubleshooting
- Known issues and how to resolve them