Skip to content

Commit 13c5184

Browse files
committed
initial
1 parent 05f5aa0 commit 13c5184

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

spec/CloudCode.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,4 +3167,18 @@ describe('afterLogin hook', () => {
31673167
const query = new Parse.Query(TestObject);
31683168
await query.find({ context: { a: 'a' } });
31693169
});
3170+
it('can send email via Parse.Cloud', async done => {
3171+
const emailAdapter = {
3172+
sendMail: mailData => {
3173+
expect(mailData).toBeDefined();
3174+
expect(mailData.to).toBe('test');
3175+
done();
3176+
},
3177+
};
3178+
await reconfigureServer({
3179+
emailAdapter: emailAdapter,
3180+
});
3181+
const mailData = { to: 'test' };
3182+
await Parse.Cloud.sendMail(mailData);
3183+
});
31703184
});

src/cloud-code/Parse.Cloud.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Parse } from 'parse/node';
22
import * as triggers from '../triggers';
3+
const Config = require('../Config');
34

45
function isParseObjectConstructor(object) {
56
return typeof object === 'function' && Object.prototype.hasOwnProperty.call(object, 'className');
@@ -528,6 +529,34 @@ ParseCloud.beforeConnect = function (handler, validationHandler) {
528529
);
529530
};
530531

532+
/**
533+
* Sends email through your mail adapter
534+
*
535+
* **Available in Cloud Code only.**
536+
*
537+
* **Requires a mail adapter to be set**
538+
*
539+
* ```
540+
* Parse.Cloud.sendMail(data);
541+
*```
542+
*
543+
* @method sendMail
544+
* @name Parse.Cloud.sendMail
545+
* @param {Any} data The object of the mail data that you'd like to send
546+
*/
547+
ParseCloud.sendMail = function (data) {
548+
const config = Config.get(Parse.applicationId) || {};
549+
const emailAdapter = config.emailAdapter;
550+
if (!emailAdapter) {
551+
throw 'You cannot send mail without an email adapter';
552+
}
553+
const sendMail = emailAdapter.sendMail;
554+
if (!sendMail || typeof sendMail !== 'function') {
555+
throw 'This adapter does not support sendMail';
556+
}
557+
return sendMail(data);
558+
};
559+
531560
/**
532561
* Registers a before live query subscription function.
533562
*

0 commit comments

Comments
 (0)