User.history和实际消息发送

时间:2016-05-25 17:06:05

标签: gmail-api

我们正在尝试知道邮件何时真正发送,并且当邮件标记为SENT时,gmail API似乎通过用户历史间接提供此信息。

但是,当用户启用UNDO功能时会出现问题:该消息标记为SENT,尽管消息尚未真正发送,但仍为事件。如果撤消,则消息已删除SENT标签并添加了DRAFT标签。

到目前为止,我们无法在历史记录中找到任何记录实际发送事件的“事件”。

我们需要处理已经发送的消息,并尽快完成,尽可能避免等待今天可用的最长撤消时间(30秒)。

关于我们如何才能完成任何提示?我们错过了什么?

1 个答案:

答案 0 :(得分:0)

你可以试试这个

例如PHP代码:

/**
* Send Message.
*
* @param Google_Service_Gmail $service Authorized Gmail API instance.
* @param string $userId User's email address. The special value 'me'
* can be used to indicate the authenticated user.
* @param Google_Service_Gmail_Message $message Message to send.
* @return Google_Service_Gmail_Message sent Message.
*/
function sendMessage($service, $userId, $message) {
try {
$message = $service->users_messages->send($userId, $message);
print 'Message with ID: ' . $message->getId() . ' sent.';
return $message;
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
}

您可以尝试获取$message->getId()如果为空,则不会发送,如果不是空消息已发送。

if($message->getId() != null){
//message has been seent

your code
}
else{

//message not been sent

your code
}

或尝试使用Advanced search,如果两者都不能正常运行您当前所做的事情,因为目前User.history没有这些功能。

您可以在此链接中查看他如何使用高级搜索来检查email is sent HTH