SXAPI Resource : sendmail
This resource allow you to send email using a MTA. Programmers can access resource methods and embed this module methods into there own method and endpoints. API developpers can use resource endpoints into there configuration profile to send mails.
This resource is based on nodejs core and is part of the sxapi-core engine from .
Resource configuration
To configure this resource, you must add a config key under the resources
section of your configuration profile.
This key must be a unique string and will be considered as the resource id. The value
must be an object who must have the appropriate configuration parameters.
For a better understanting of the sxapi configuration profile, please refer to the configuration guide
Resource config parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
_class | yes | string | module name. Must be sendmail for this resource | |
transport | yes | object | object describing the transport method | |
message | no | object | object with default messages options |
Example
This is a sample configuration of this resource. You must add this section under
the resources
section of your configuration profile
resources:
sendmail-id:
_class: sendmail
transport:
host: localhost
port: 465
secure: true
auth:
user: myUser
pass: myPwd
messages:
from: my@email.org
to: my@email.org
Resource methods
If you want to use this resource in our own module, you can retrieve this resource
instance by using $app.resources.get('sendmail-id')
where sendmail-id
is the
id of your resource as defined in the resource configuration.
This module come with one single method.
Method sendMail
send mail using the MTA configured and return a description of the sended message.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
mailOptions | yes | object | object describing the message to send | |
callback | no | function | default | callback function called when application get result. If not defined, dropped to a default function who output information to the debug console |
callback(error,response) | N/A | mixed | null | will be false or null if no error returned from the application. Will be a string message describing a problem if an error occur. |
callback(error,response) | N/A | mixed | the application object (if no error) |
Example
var resource = $app.resources.get('sendmail-id');
resource.sendMail({
"from": "my@email.org",
"to": "my@email.org",
"subject": "default subject",
"text": "default message"
}, function (error, response) {
console.log(error, response);
});
Resource endpoints
This module come with a single endpoint.
sendMail endpoint
The purpose of this endpoint is to send a mail when called.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
path | yes | string | path used as client endpoint (must start with /) | |
resource | yes | string | resource id declared in the resource of your config profile | |
endpoint | yes | string | endpoint name declared in the resource module. In this case must be "info" | |
other | no | all other params will be used as message options before sending it to the server |
Example
server:
endpoints:
- path: "/info"
resource: sendmail-id
endpoint: sendMail
to: my@email.org
subject: default subject
text: default message