【发布时间】:2013-06-26 08:53:10
【问题描述】:
我被要求使用外部 SMTP 服务器,说明如下:
“我们希望您以明文形式连接到端口 25,然后发出 STARTTLS 以开始 TLS/SSL。然后登录”
这可能吗?如果可以,我应该怎么做?据我了解,这与在 smtp 连接数组中将 TLS 设置为 true 不同,对吗?
更新 在这里向胜利迈进。查看 SmtpTransport.php 中的代码,我可以看到它与 cmets 中链接的规范相匹配(显然),但块 102-107 似乎将主机设置为客户端或本地主机 - 我在主机配置。我做错了吗?
蛋糕代码:
protected function _connect() {
$this->_generateSocket();
if (!$this->_socket->connect()) {
throw new SocketException(__d('cake_dev', 'Unable to connect to SMTP server.'));
}
$this->_smtpSend(null, '220');
if (isset($this->_config['client'])) {
$host = $this->_config['client'];
} elseif ($httpHost = env('HTTP_HOST')) {
list($host) = explode(':', $httpHost);
} else {
$host = 'localhost';
}
try {
$this->_smtpSend("EHLO {$host}", '250');
if ($this->_config['tls']) {
$this->_smtpSend("STARTTLS", '220');
$this->_socket->enableCrypto('tls');
$this->_smtpSend("EHLO {$host}", '250');
}
} catch (SocketException $e) {
if ($this->_config['tls']) {
throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.'));
}
try {
$this->_smtpSend("HELO {$host}", '250');
} catch (SocketException $e2) {
throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection.'));
}
}
}
我的电子邮件配置:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('me@example.com' => 'my name'),
'host' => 'secretipaddress',
'port' => 25,
'timeout' => 30,
'username' => 'me@example.com',
'password' => 'secretpassword',
'client' => null,
'log' => true,
'tls' => true
);
【问题讨论】:
-
听起来像是一个不了解电子邮件解释电子邮件的人 - ref 将 tls 设置为 true 是否“正常工作”? SMTP 是一个标准协议,没有人可能实现它的非标准排列。
-
不,它没有。但这听起来可能是防火墙问题之类的其他问题,一旦修复,它可能会将 tls 设置为 true。我会尝试更多并报告:)谢谢安迪。
-
ps,感谢您的链接,令人惊讶的是,阅读手册会使事情变得更清晰。
-
=) 您可能会发现使用任何邮件客户端(apple mail、thunderbird、gmail 等)发送测试邮件并在此过程中确认正确的设置很有用。
-
用更多的思考和细节更新 Q