使用SwiftMailer将邮件添加到Send文件夹

Rot*_*adu 4 php email swiftmailer

我正在从swiftmailer.org使用SwiftMailer for PHP

一切运作良好,但我想知道是否有办法将发送的邮件从SwiftMailer发送的邮件帐户添加到已发送的文件夹中?

这就是全部,祝你有个美好的一天.

小智 9

根据开发人员的说法,swiftmailer无法复制到Sent文件夹,因为它是邮件发件人而不是邮箱管理器.

github页面所述:

Swiftmailer是一个发送电子邮件的库,而不是管理邮箱.所以,这确实超出了Swiftmailer的范围.

但是,来自php.net的人发布了一个可能适合您的解决方案:

  1. 使用SwiftMailer通过PHP发送消息.

    $message = Swift_Message::newInstance("Subject goes here");
    // (then add from, to, body, attachments etc)
    $result = $mailer->send($message);
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在上面的步骤1)中构造消息时,将其保存到变量,如下所示:

    $msg = $message->toString(); 
    //  (this creates the full MIME message required for imap_append()!!
    //  After this you can call imap_append like this:
    imap_append($imap_conn,$mail_box,$msg."\r\n","\\Seen"); 
    
    Run Code Online (Sandbox Code Playgroud)


fri*_*rin 7

我遇到了类似的问题,Sutandiono 的回答让我找到了正确的方向。但是,由于完整性以及连接到 Exchange 2007 服务器的其他问题,我想提供一个完整的代码段,用于将消息存储到 IMAP 上的已发送文件夹:

$msg = $message->toString();
// $message is instance of Swift_Message from SwiftMailer

$stream = imap_open("{mail.XXXXX.org/imap/ssl/novalidate-cert}", "username", "password", null, 1, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
// connect to IMAP SSL (port 993) without Kerberos and no certificate validation

imap_append($stream,"{mail.XXXXX.org/imap/ssl/novalidate-cert}Sent Items",$msg."\r\n","\\Seen");
// Saves message to Sent folder and marks it as read

imap_close($stream);
// Close connection to the server when you're done
Run Code Online (Sandbox Code Playgroud)

用您自己的信息替换服务器主机名、用户名和密码。