Send Mail Over REST
Although you are more likely to send mail from a script in production, you can send email using the REST API by sending an HTTP POST to /openidm/external/email
, to test that your configuration works. You pass the message parameters as part of the POST payload, URL encoding the content as necessary.
The following example sends a test email using the REST API:
curl \ --header "Content-Type: application/json" \ --header "X-OpenIDM-Username: openidm-admin" \ --header "X-OpenIDM-Password: openidm-admin" \ --header "Accept-API-Version: resource=1.0" \ --request POST \ --data '{ "from":"openidm@example.com", "to":"your_email@example.com", "subject":"Test", "body":"Test"}' \ "http://localhost:8080/openidm/external/email?_action=send"
{ "status": "OK", "message": "Email sent" }
By default, a response is returned only when the SMTP relay has completed. To return a response immediately, without waiting for the SMTP relay to finish, include the parameter waitForCompletion=false
in the REST call. Use this option only if you do not need to verify that the email was accepted by the SMTP server. For example:
curl \ --header "Content-Type: application/json" \ --header "X-OpenIDM-Username: openidm-admin" \ --header "X-OpenIDM-Password: openidm-admin" \ --header "Accept-API-Version: resource=1.0" \ --request POST \ --data '{ "from":"openidm@example.com", "to":"your_email@example.com", "subject":"Test", "body":"Test"}' \ "http://localhost:8080/openidm/external/email?_action=send&waitForCompletion=false"
{ "status": "OK", "message": "Email submitted" }