Mailkit:我可以从转发的电子邮件中获取原始发件人吗?

时间:2017-03-14 12:23:52

标签: c# .net imap mailkit

我正在管理转发的电子邮件,并注意到如果我执行TextSearchQuery(SearchTerm.FromContains, "test@test.com")我只是获取转发器的UniqueIds,而不是电子邮件的原始发件人。

我知道我可以潜入TextBodyHtmlBody并查看“来自”,但这可能会因客户语言等而有所不同,所以我想知道是否是否有任何方法来执行“深度SearchQuery”。

有很多SearchTermSearchTerm.OriginalFromContains可能很有趣,如果它还不存在的话!

感谢。

2 个答案:

答案 0 :(得分:1)

因为IMAP不支持,所以没办法做你想做的事。 MailKit的搜索API仅限于IMAP协议的搜索功能(不幸的是,它很有限)。

答案 1 :(得分:1)

这不是防火解决方案,但实际上我在电子邮件中搜索所有“mailTo”,我列出它们,并且我给用户选择了排除列表的具体域名。

我终于拿到了最后一封邮件。

private string ExtractMailTo(string html, string domainToExclude)
{
    try
    {   //Searches for mailTos with regEx
        //If user didn't pass any domain we will just ignore it
        //and pick up the last mailTo.
        bool deleteDomainUser = (!string.IsNullOrEmpty(domainToExclude)
            || !string.IsNullOrWhiteSpace(domainToExclude));

        var mailTos = new List<String>();
        string pattern = @"mailto\s*:\s*([^""'>]*)";
        foreach (Match match in Regex.Matches(html, pattern))
            mailTos.Add(match.Groups[1].Value);

        if(deleteDomainUser)
            //We search for the domain concreted by the user
            //and we delete it from the mailTos List
            mailTos.RemoveAll(doms => doms.Contains(domainToExclude));
        var last = mailTos.Last();
        return last;
    }
    catch (Exception ex)
    {
        string message = "A problem ocurred parsing the e-mail body searching for MailTos. \n" 
                + ex.Message;
        throw new Exception(message, ex);
    }
}

希望它对某人有帮助。

相关问题