Welcome to the Protogrid Developer Wiki. A place to gather all the documentation and tips&tricks regarding Protogrid.

JSON API Endpoint mailsend

/api/v2/apps/<app_name>/mailsend

[GET, POST] Send an email using the provided data

The following JSON data fields or URL parameters can be used:

  • to: TO address (multiple addresses separated by comma)
  • cc: CC address (multiple addresses separated by comma)
  • bcc: BCC address (multiple addresses separated by comma)
  • replyto: ReplyTo address
  • subject: Subject in plain text
  • body: Body text in plain text format (URL encoded)
  • bodyhtml: Body text in HTML format (URL encoded). If both body and bodyhtml are specififed, only bodyhtml will be used
  • attachments: weblink to attachment (URL encoded), multiple links separated by comma

Combinations of JSON data fields and URL parameters are allowed, whereas JSON data fields take precendence over URL parameters

The mail will be sent according to the currently logged in user (mail address specified in user profile, and the fields “SMTP Server Hostname”, “SMTP Server Port” and “SMTP Server Password”).

The function will fist try to establish a TLS session to the specified mail server and authenicate using the supplies credentials. If TLS is not available it will try to connect using SSL. Finally if SSL is not available the function tries to connect using unsecured SMTP protocol.

The returned result will contain the key success with a value of true or a corresponding error message.

Example request:

https://example.protogrid.com/api/v2/apps/example/mailsend?to=user1@example.com&cc=user2@example.com&subject=example&bcc=user@example.com&replyto=user@example.com&body=&bodyhtml=%3Chtml%3E%0A%3Cbody%3E%0A%0A%3Ch1%3EMy%20First%20Heading%3C%2Fh1%3E%0A%3Cp%3EMy%20first%20paragraph.%3C%2Fp%3E%0A%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E&attachments=https%3A%2F%2Fprotogrid.wiki%2Flib%2Ftpl%2Fpgrid-vector%2Fuser%2Flogo.png

Example result:

{
   "errors" : [],
   "protogrid_environment_version" : "2.1.3",
   "result": {"success":true}
}

Example client-side jQuery function to send mail in web application

$.get("https://example.protogrid.com/api/v2/apps/example/mailsend?to=user@example.com&subject=Test&body=This%20is%20a%20testmessage", function(data, status){
    alert("Data: " + JSON.stringify(data));
  });
 
$.post({
    url: "https://example.protogrid.com/api/v2/apps/example/mailsend",
    data: JSON.stringify({
		"to": "user@example.com",
		"cc": "user2@example.com",
		"subject": "Test",
		"body": "This%20is%20a%20testmessage",
		}),
    contentType: 'application/json; charset=utf-8'
}).done(function (response) {
        alert("Data: " + JSON.stringify(response));
});
Print/export