forked from postalserver/postal-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendMessage.js
74 lines (59 loc) · 1.73 KB
/
SendMessage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var SendResult = require('./SendResult');
function SendMessage(client) {
this.attributes = {
to: [],
cc: [],
bcc: [],
headers: {},
attachments: []
};
this.client = client;
}
SendMessage.prototype.to = function to(address) {
this.attributes.to.push(address);
};
SendMessage.prototype.cc = function cc(address) {
this.attributes.cc.push(address);
};
SendMessage.prototype.bcc = function bcc(address) {
this.attributes.bcc.push(address);
};
SendMessage.prototype.from = function from(address) {
this.attributes.from = address;
};
SendMessage.prototype.sender = function sender(address) {
this.attributes.sender = address;
};
SendMessage.prototype.subject = function subject(_subject) {
this.attributes.subject = _subject;
};
SendMessage.prototype.tag = function tag(_tag) {
this.attributes.tag = _tag;
};
SendMessage.prototype.replyTo = function replyTo(_replyTo) {
this.attributes.reply_to = _replyTo;
};
SendMessage.prototype.plainBody = function plainBody(content) {
this.attributes.plain_body = content;
};
SendMessage.prototype.htmlBody = function htmlBody(content) {
this.attributes.html_body = content;
};
SendMessage.prototype.header = function header(key, value) {
this.attributes.headers[key] = value;
};
SendMessage.prototype.attach = function attach(filename, contentType, data) {
var attachment = {
content_type: contentType,
data: new Buffer(data).toString('base64'),
name: filename
};
this.attributes.attachments.push(attachment);
};
SendMessage.prototype.send = function send() {
return this.client.makeRequest('send', 'message', this.attributes)
.then(function (result) {
return new SendResult(this.client, result);
}.bind(this));
};
module.exports = SendMessage;