Mailkit:我可以从转发的电子邮件中找到原始发件人吗?
Mailkit: Could I get the original sender from a forwarded e-mail?
我正在管理转发的电子邮件,并注意到如果我执行 TextSearchQuery(SearchTerm.FromContains, "test@test.com")
我只会得到转发者的 UniqueId,而不是电子邮件的原始发件人。
我知道我可以深入 TextBody
或 HtmlBody
并查看 "from",但这可能因客户的语言等而异,所以我想知道是否有任何方法可以执行 "deep SearchQuery".
有很多 SearchTerm
,但是 SearchTerm.OriginalFromContains
可能很有趣,如果它还不存在的话!
谢谢。
由于 IMAP 不支持,因此无法执行您想要的操作。 MailKit 的搜索 API 仅限于 IMAP 协议的搜索功能(不幸的是,它相当有限)。
这不是一个防火解决方案,但我实际上搜索了电子邮件中的所有 "mailTo",我列出了它们,并让用户可以选择排除列表的具体域。
我终于拿起了最后一个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);
}
}
希望对大家有所帮助。
我正在管理转发的电子邮件,并注意到如果我执行 TextSearchQuery(SearchTerm.FromContains, "test@test.com")
我只会得到转发者的 UniqueId,而不是电子邮件的原始发件人。
我知道我可以深入 TextBody
或 HtmlBody
并查看 "from",但这可能因客户的语言等而异,所以我想知道是否有任何方法可以执行 "deep SearchQuery".
有很多 SearchTerm
,但是 SearchTerm.OriginalFromContains
可能很有趣,如果它还不存在的话!
谢谢。
由于 IMAP 不支持,因此无法执行您想要的操作。 MailKit 的搜索 API 仅限于 IMAP 协议的搜索功能(不幸的是,它相当有限)。
这不是一个防火解决方案,但我实际上搜索了电子邮件中的所有 "mailTo",我列出了它们,并让用户可以选择排除列表的具体域。
我终于拿起了最后一个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);
}
}
希望对大家有所帮助。