Skip to content

Commit 7b3d3f3

Browse files
authored
add sender to sendToSMTP
1 parent f8f5666 commit 7b3d3f3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

sendmail.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports = function (options) {
123123
}
124124
}
125125

126-
function sendToSMTP (domain, srcHost, from, recipients, body, cb) {
126+
function sendToSMTP (domain, srcHost, from, recipients, body, sender, cb) {
127127
const callback = (typeof cb === 'function') ? cb : function () {};
128128
connectMx(domain, function (err, sock) {
129129
if (err) {
@@ -170,7 +170,11 @@ module.exports = function (options) {
170170
}
171171
*/
172172

173-
queue.push('MAIL FROM:<' + from + '>');
173+
if(sender){
174+
queue.push('MAIL FROM:' + sender + ' <' + from + '>');
175+
} else {
176+
queue.push('MAIL FROM:<' + from + '>');
177+
}
174178
const recipients_length = recipients.length;
175179
for (let i = 0; i < recipients_length; i++) {
176180
queue.push('RCPT TO:<' + recipients[i] + '>');
@@ -352,6 +356,7 @@ module.exports = function (options) {
352356
let recipients = [];
353357
let groups;
354358
let srcHost;
359+
let sender;
355360
if (mail.to) {
356361
recipients = recipients.concat(getAddresses(mail.to));
357362
}
@@ -363,6 +368,10 @@ module.exports = function (options) {
363368
if (mail.bcc) {
364369
recipients = recipients.concat(getAddresses(mail.bcc));
365370
}
371+
372+
if (mail.sender) {
373+
sender = mail.sender
374+
}
366375

367376
groups = groupRecipients(recipients);
368377

@@ -384,7 +393,7 @@ module.exports = function (options) {
384393
message = signature + '\r\n' + message;
385394
}
386395
for (let domain in groups) {
387-
sendToSMTP(domain, srcHost, from, groups[domain], message, callback);
396+
sendToSMTP(domain, srcHost, from, groups[domain], message, sender, callback);
388397
}
389398
});
390399
}

0 commit comments

Comments
 (0)