节点 sendmail opendkim mail.private 权限被拒绝

问题描述

您好,我想在发送之前在我的 ubuntu 服务器上用私钥签署电子邮件。 我安装了 node 和 sendmail 包。 代码如下:

var fs = require('fs');
var sendmail = require('sendmail')({
    silent: true,dkim: {
      privateKey: fs.readFileSync('/etc/opendkim/keys/example.com/mail.private','utf8'),keySelector: 'mail'
    }
  })

在我的服务器上,文件 /etc/opendkim/keys/example.com/mail.private 有 chmod 600 和 chown opendkim:opendkim。 当我跑步时:

sendmail({
        from: 'test@example.com',to: 'address@ethereal.email',subject: 'subject',html: html,},function(err,reply) {
        console.log(err && err.stack);
    });

它不起作用。在日志中出现此错误错误:EACCES:权限被拒绝,打开“/etc/opendkim/keys/example.com/mail.private” 这里有什么问题? 我知道问题出在权限上。问题是如何正确地做到这一点,而不改变 chmod 超过 600。

解决方法

就我而言,问题出在路径上。密钥的路径必须完全像这样 /etc/opendkim/keys/mail.private

还有我正在工作的 /etc/opendkim.conf 文件:

AutoRestart             Yes
AutoRestartRate         10/1h
Syslog                  yes
UMask                   002
SyslogSuccess           Yes
LogWhy                  Yes
Canonicalization        relaxed/simple
PidFile                 /var/run/opendkim/opendkim.pid
SignatureAlgorithm      rsa-sha256
ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
UserID opendkim:opendkim
Mode                    sv
OversignHeaders         From
Domain                  [edited domain]
KeyFile                 /etc/opendkim/keys/mail.private
Selector                mail
SOCKET                  inet:8891@127.0.0.1