如何知道它是Microsoft Graph中的自动回复邮件?

时间:2017-12-06 22:01:57

标签: outlook microsoft-graph

我正在使用Microsoft Graph API来获取邮件。

GET /v1.0/me/messages

返回

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('576552d5-3bc0-42a6-a23d-bfceb405db23')/messages",
    "@odata.nextLink": "https://graph.microsoft.com/v1.0/me/messages?$skip=11",
    "value": [
        {
            "@odata.etag": "W/\"HwAAABYAAACpTc/InBsuTYwTUBb+VIb4AACqi2tx\"",
            "id": "AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI2MgBGAAAAAACUbnk-iwQZRbXMgkfKtmYhBwCpTc-InBsuTYwTUBb_VIb4AAAAAAEMAACpTc-InBsuTYwTUBb_VIb4AACqNTk9AAA=",
            "createdDateTime": "2017-12-06T21:57:09Z",
            "lastModifiedDateTime": "2017-12-06T21:57:19Z",
            "changeKey": "HwAAABYAAACpTc/InBsuTYwTUBb+VIb4AACqi8tx",
            "categories": [],
            "receivedDateTime": "2017-12-06T21:57:09Z",
            "sentDateTime": "2017-12-06T21:56:16Z",
            "hasAttachments": false,
            "internetMessageId": "<e74a536a53d245e49d779d47f774f4a0@CO2PR00MB0214.namprd00.prod.outlook.com>",
            "subject": "Automatic reply: Hi",
            "bodyPreview": "I am OOF.",
            "importance": "normal",
            "parentFolderId": "AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA2ODZlMDI5MgAuAAAAAACUbnk-iwQZRbXMgkfKtmYhAQCpTc-InBsuTYwTUBb_VIb4AAAAAAEMAAA=",
            "conversationId": "AAQkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA2ODZlMDI5MgAQAPekscpearpHmBFbhG0DKuc=",
            "isDeliveryReceiptRequested": null,
            "isReadReceiptRequested": false,
            "isRead": true,
            "isDraft": false,
            "webLink": "https://outlook.office365.com/owa/?ItemID=AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgBGAAAAAACUbnk%2FiwQZRbXMgkfKtmYhBwCpTc%2FInBsuTYwTUBb%2BVIb4AAAAAAEMAACpTc%2FInBsuTYwTUBb%2BVIb4AACqNTk2AAA%3D&exvsurl=2&viewmodel=ReadMessageItem",
            "inferenceClassification": "focused",
            "body": {
                "contentType": "html",
                "content": "hi"
            },
            "sender": {
                "emailAddress": {
                    "name": "Jack",
                    "address": "jack@example.com"
                }
            },
            "from": {
                "emailAddress": {
                    "name": "Jack",
                    "address": "jack@example.com"
                }
            },
            "toRecipients": [
                {
                    "emailAddress": {
                        "name": "Rose",
                        "address": "rose@example.com"
                    }
                }
            ],
            "ccRecipients": [],
            "bccRecipients": [],
            "replyTo": []
        }
    ]
}

我没有找到任何相关字段来确定它是否是自动回复邮件。

现在我正在使用

mail.subject.startsWith('Automatic reply:')

确定是否在代码中自动回复邮件。

但是,它不可靠。因为有时候我会收到以Resposta automática:等其他语言开头的邮件。

那么如何知道它是正确的自动回复邮件?

3 个答案:

答案 0 :(得分:3)

我不是专家,但我不相信有任何方法可以确定电子邮件是否是自动回复,除非该电子邮件实际上包含一个字符串“这是一个自动回复”或其他内容。

答案 1 :(得分:3)

正如@Horkrine所说,没有官方保证的方法来检测电子邮件是否是自动回复。

但有两种方法可能有用:

方法1:检测响应时间

如果您有能力,请考虑检查发送的电子邮件与回复之间的时间。如果该时间在某个阈值内,则几乎可以肯定是自动回复。例如,考虑在几秒钟内收到回复。这与现代垃圾邮件机器人检测技术有很多相关性。

方法2:关键字

另一种方法是查找关键字,就像现在一样。但是,您还必须考虑其他语言,拼写错误,拼写错误等。您将无法获得所有内容。

例如:

mail.subject.contains('Automatic') OR mail.subject.contains('Auto-matic') OR mail.subject.contains('Away') OR mail.subject.contains('out of office') ... OR mail.subject.contains('automática') ...

我不建议输入这样的列表,而是建议在互联网上进行快速搜索,看看是否有任何此类列表可以复制粘贴,因为有些人之前已经做过这类事情并且有一些免费的代码。

答案 2 :(得分:1)

刚刚找到了另一个有趣的API getMailTips,但这只能帮助确定其他用户是Outlook或Office 365用户时的自动邮件。

为方便起见,复制下面的演示。

POST https://graph.microsoft.com/api/beta/users/{id|userPrincipalName}/getMailTips

{
    "EmailAddresses": [
        "danas@contoso.onmicrosoft.com", 
        "fannyd@contoso.onmicrosoft.com"
    ],
    "MailTipsOptions": "automaticReplies, mailboxFullStatus"
}

它将返回类似

的内容
{
    "@odata.context":"https://graph.microsoft.com/api/beta/$metadata#Collection(microsoft.graph.mailTips)",
    "value":[
        {
            "emailAddress":{
                "name":"",
                "address":"danas@contoso.onmicrosoft.com"
            },
            "automaticReplies":{
                "message":"<style type=\"text/css\" style=\"\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n<div dir=\"ltr\">\r\n<div id=\"x_divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\">\r\n<p>Hi, I am on vacation right now. I'll get back to you after I return.<br>\r\n</p>\r\n</div>\r\n</div>",
                "messageLanguage":{
                    "locale":"en-US",
                    "displayName":"English (United States)"
                }
            },
            "mailboxFull":false
        },
        {
            "emailAddress":{
                "name":"",
                "address":"fannyd@contoso.onmicrosoft.com"
            },
            "automaticReplies":{
                "message":""
            },
            "mailboxFull":false
        }
    ]
}