问题
I'm trying to reply to a specific thread with Gmail API.
Here's my code:
$strRawMessage = "From: Firstname lastname <".$userId.">\r\n";
$strRawMessage .= "To: Firstname lastname <tomail@gmail.com>\r\n";
$strRawMessage .= 'Subject: =?utf-8?B?' . base64_encode("Heres my test message") . "?=\r\n";
$strRawMessage .= "MIME-Version: 1.0\r\n";
$strRawMessage .= "Content-Type: text/html; charset=utf-8\r\n";
$strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n";
$strRawMessage .= "this <b>is a test message!\r\n";
$mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
$msg = new Google_Service_Gmail_Message();
$msg->setRaw($mime);
$msg->setThreadId( $threadId );
$response = $this->service->users_messages->send($userId, $msg);
It sends the mail to the correct mail address but won't send it to the thread specified with "threadId".
my threadId is 100% correct.
回答1:
Check the Sending messages documentation
If you're trying to send a reply and want the email to thread, make sure that:
- The Subject headers match
- The References and In-Reply-To headers follow the RFC 2822 standard.
Those are the parts you may be missing since you're almost correct.
来源:https://stackoverflow.com/questions/45962805/reply-to-a-specific-thread