【问题标题】:Adding message to IMAP folder using ZF3使用 ZF3 将消息添加到 IMAP 文件夹
【发布时间】:2018-12-15 10:29:01
【问题描述】:

我正在尝试使用 Zend Framework 3 将新消息添加到 IMAP 文件夹。 我使用的代码如下:

...
$draftMessage = new \Zend\Mail\Storage\Message([
  'headers' => [
    'subject' => 'voyteck0@gmail.com',
  ],
  'content' => 'ala ma kota',
]);  
[valid-imap-connection]->appendMessage($draftMessage, 'Drafts', [\Zend\Mail\Storage::FLAG_DRAFT]);
...

但是我总是抛出异常: Zend\Mail\Storage\Exception\RuntimeException:'cannot create message, please check if the folder is exists and your flags' throw in /.../zendframework/zend-mail/src/Storage/Imap.php(480)

我在这里还使用了一个伪元素 [valid-imap-connection] 来避免模糊问题 - 但连接工作正常(检索消息、发送消息、在文件夹之间移动等)

文件夹存在 - 我已经在 ZF 中进行了一些调试,发现在第 480 行中,该命令在上述代码中返回 NULL。如果我将文件夹更改为不存在的文件夹 - 它返回 false。 异常本身被抛出一次(!结果) - 所以 null 也适用于这种情况。

但是,即使我删除了引发异常的代码(并且代码使用该 NULL 值完成执行) - 消息仍然没有出现在文件夹中(直接在磁盘上检查)。 Dovecot 日志中没有什么有趣的内容(除了连接已成功建立)。

非常欢迎任何想法:)

【问题讨论】:

    标签: zend-framework imap zend-framework3 dovecot zend-mail


    【解决方案1】:

    我认为问题出在两件事上:

    1. 我应该使用 \Zend\Mail\Message 类(不是 ...\Storage... 类)
    2. draftMessage 应该是一个字符串版本(实际上不知道为什么 - 因为 appendMessage 已经使用了 toString() 函数)

    所以有效的代码如下:

    ...
    $draftMessage = new \Zend\Mail\Message();  
    $draftMessage->setSubject('voyteck0@gmail.com');
    $draftMessage->setBody('ala ma kota');
    [valid-imap-connection]->appendMessage($draftMessage->toString(), 'Drafts', [\Zend\Mail\Storage::FLAG_DRAFT]);
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 2010-10-10
      • 1970-01-01
      • 2012-04-28
      • 2014-11-24
      • 1970-01-01
      相关资源
      最近更新 更多