如何在回复时附加线程消息以便新用户可以在 Gmail 中看到之前的对话 Api
How to append thread messages while reply so that new user can see previous conversation in Gmail Api
我想从 Gmail Api 发送回复邮件,一切顺利,邮件被串接或附加到收件人邮箱(A 和 B 用户)。但是,如果我添加新的 CC 用户(我们命名为 C),那么新用户应该会看到之前在 A 和 B 之间交流的线程消息。
如果有人知道解决办法请帮帮我
<?php
$client = getClient();
$gmail = new Google_Service_Gmail($client);
$message = new Google_Service_Gmail_Message();
$optParam = array();
$referenceId = '';
$thread = $gmail->users_threads->get('someid@gmail.com', $threadId);
$optParam['threadId'] = '16c632fd24536690';
$threadMessages = $thread->getMessages($optParam);
$messageId = $threadMessages[0]->getId();
$subject = "Re: Thread mail test";
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->From = $from_email;
$mail->FromName = $from_name;
$mail->addCustomHeader('In-Reply-To',
'<CAAdsdfsdf890sdjfklG4rJzoepBbWn3Crhq9sdfGq6kg@mail.gmail.com>');
$mail->addCustomHeader('References',
'<CAAdsdfsdf890sdjfklG4rJzoepBbWn3Crhq9sdfGq6kg@mail.gmail.com>');
$mail->addAddress($to);
$mail->addcc($cc);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
$raw = rtrim(strtr(base64_encode($mime), '+/', '-_'), '=');
$message->setRaw($raw);
$message->setThreadId($threadId);
$response = $gmail->users_messages->send($userId, $message);
?>
使用 Google Apps 脚本代替 Gmail API
将允许您使用 message.forward
发送线程的所有消息。您可以通过
来实现它
- 列出所有带
thread.getMessages()
的线程消息
- 使用
threadMessages[threadMessages.length-1]
获取最后一条线程消息
- 使用
message.forward()
将最后一条线程消息转发给所需的收件人(A、B 和 C)
如果您想坚持使用 Gmail API,我能想到的解决方法是
- 获取所有线程消息
- 获取原始内容
- 将每个线程消息的原始内容附加到要发送的消息正文中
一个例子:
function myFunction() {
var myThread = GmailApp.getThreadById("PASTE HERE THE THREAD ID");
var threadMessages = MyThread.getMessages();
var lastMessage = threadMessages[threadMessages.length-1];
lastMessage.forward("emailA", "emailB", "emailC");
}
在线程中发送消息的简单方法是
1.邮件正文应该是这样的
2。将消息转换为 base64 编码。
3。使用 https://developers.google.com/gmail/api/v1/reference/users/messages/send 使用 thread-id 发送电子邮件。
4.enjoy编码.
我想从 Gmail Api 发送回复邮件,一切顺利,邮件被串接或附加到收件人邮箱(A 和 B 用户)。但是,如果我添加新的 CC 用户(我们命名为 C),那么新用户应该会看到之前在 A 和 B 之间交流的线程消息。
如果有人知道解决办法请帮帮我
<?php
$client = getClient();
$gmail = new Google_Service_Gmail($client);
$message = new Google_Service_Gmail_Message();
$optParam = array();
$referenceId = '';
$thread = $gmail->users_threads->get('someid@gmail.com', $threadId);
$optParam['threadId'] = '16c632fd24536690';
$threadMessages = $thread->getMessages($optParam);
$messageId = $threadMessages[0]->getId();
$subject = "Re: Thread mail test";
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->From = $from_email;
$mail->FromName = $from_name;
$mail->addCustomHeader('In-Reply-To',
'<CAAdsdfsdf890sdjfklG4rJzoepBbWn3Crhq9sdfGq6kg@mail.gmail.com>');
$mail->addCustomHeader('References',
'<CAAdsdfsdf890sdjfklG4rJzoepBbWn3Crhq9sdfGq6kg@mail.gmail.com>');
$mail->addAddress($to);
$mail->addcc($cc);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
$raw = rtrim(strtr(base64_encode($mime), '+/', '-_'), '=');
$message->setRaw($raw);
$message->setThreadId($threadId);
$response = $gmail->users_messages->send($userId, $message);
?>
使用 Google Apps 脚本代替 Gmail API
将允许您使用 message.forward
发送线程的所有消息。您可以通过
- 列出所有带
thread.getMessages()
的线程消息
- 使用
threadMessages[threadMessages.length-1]
获取最后一条线程消息
- 使用
message.forward()
将最后一条线程消息转发给所需的收件人(A、B 和 C)
如果您想坚持使用 Gmail API,我能想到的解决方法是
- 获取所有线程消息
- 获取原始内容
- 将每个线程消息的原始内容附加到要发送的消息正文中
一个例子:
function myFunction() {
var myThread = GmailApp.getThreadById("PASTE HERE THE THREAD ID");
var threadMessages = MyThread.getMessages();
var lastMessage = threadMessages[threadMessages.length-1];
lastMessage.forward("emailA", "emailB", "emailC");
}
在线程中发送消息的简单方法是
1.邮件正文应该是这样的
2。将消息转换为 base64 编码。
3。使用 https://developers.google.com/gmail/api/v1/reference/users/messages/send 使用 thread-id 发送电子邮件。
4.enjoy编码.