From 83b11547692dae5ec980d96f6382df10079ef936 Mon Sep 17 00:00:00 2001 From: petersirka Date: Mon, 28 Oct 2024 10:44:50 +0100 Subject: [PATCH] =?UTF-8?q?Extended=20`Mail.from(email,=20[name])`=20metho?= =?UTF-8?q?d=20by=20adding=20`name`=20argument=20by=20Marek=20Mr=C3=A1z.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.txt | 2 ++ index.js | 2 +- mail.js | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 89af6a2..7bd05ae 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,8 @@ - reduced DNS cache flush time to 3 minutes - added `$.address` property with the absolute URL address - added `$.ctrl(ctrl_instance)` method +- extended `Mail.from(email, [name])` method by adding `name` argument by [Marek Mráz](https://github.com/Mrazbb) +- added `CONF.mail_from_name {String}` option ======================== 0.0.6 diff --git a/index.js b/index.js index 08c1f4a..b281259 100644 --- a/index.js +++ b/index.js @@ -460,7 +460,7 @@ function unlink(arr, callback) { } else msg.to(email); - msg.from(F.config.mail_from || F.config.smtp.from || F.config.smtp.user); + msg.from(F.config.mail_from || F.config.smtp.from || F.config.smtp.user, F.config.mail_from_name); callback && msg.callback(callback); if (reply) diff --git a/mail.js b/mail.js index ed8907c..bb30f46 100755 --- a/mail.js +++ b/mail.js @@ -60,8 +60,9 @@ Message.prototype.callback = function(fn) { return this; }; -Message.prototype.sender = Message.prototype.from = function(email) { +Message.prototype.sender = Message.prototype.from = function(email, name) { this.email_from = email; + this.email_from_name = name; return this; }; @@ -571,7 +572,7 @@ Mailer.$writemessage = function(obj, buffer) { self.$priority && message.push('X-Priority: ' + self.$priority); self.$confidential && message.push('Sensitivity: Company-Confidential'); - message.push('From: <' + msg.email_from + '>'); + message.push('From: ' + (msg.email_from_name ? (unicode_encode(msg.email_from_name) + ' <' + msg.email_from + '>') : msg.email_from)); if (msg.headers) { for (let key in msg.headers)