我在C#.NET 4.0中创建了一个Outlook 2007加载项。
我想在C#代码中阅读安全发件人列表。
if (oBoxItem is Outlook.MailItem)
{
Outlook.MailItem miEmail = (Outlook.MailItem)oBoxItem;
OlDefaultFolders f = Outlook.OlDefaultFolders.olFolderContacts;
if (miEmail != null)
{
string body = miEmail.Body;
double score = spamFilterObject.CalculateSpamScore(body);
if (score <= 0.9)
{
miEmail.Move(mfJunkEmail);
}
}
}
因此,上述代码会将所有电子邮件移至垃圾邮件,即使它们存在于安全发件人列表中。因此,我希望获得安全的发件人列表,以便我可以避免这种垃圾邮件检查。
有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
Outlook对象模型不公开这些列表(原因或多或少)。安全发件人列表可以直接从注册表中读取:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\[PROFILE NAME]\0a0d020000000000c000000000000046\001f0418
此二进制注册表项包含双字节字符,以分号(;)分隔。
映射到此注册表项的MAPI属性是 PR_SPAM_TRUSTED_SENDERS_W,记录在案here。
答案 1 :(得分:0)
Chavan,我认为,因为这已经超过4年没有更新,你不需要更多的信息,但这个问题和答案帮助我找到了我想要的东西(这很难找到)并且让我编写下面的代码,如果您仍然在寻找答案,这可能有所帮助。
此代码在LINQPad中运行,因此如果您不是LINQPad用户,请删除.Dump()方法并替换为Console.WriteLine或Debug.WriteLine。
干杯!
const string valueNameBlocked = "001f0426";
const string valueNameSafe = "001f0418";
// Note: I'm using Office 2013 (15.0) and my profile name is "Outlook"
// You may need to replace the 15.0 or the "Outlook" at the end of your string as needed.
string keyPath = @"Software\Microsoft\Office\15.0\Outlook\Profiles\Outlook";
string subKey = null;
var emptyBytes = new byte[] { };
var semi = new[] { ';' };
string blocked = null, safe = null;
// I found that my subkey under the profile was not the same on different machines,
// so I wrote this block to look for it.
using (var key = Registry.CurrentUser.OpenSubKey(keyPath))
{
var match =
// Get the subkeys and all of their value names
key.GetSubKeyNames().SelectMany(sk =>
{
using (var subkey = key.OpenSubKey(sk))
return subkey.GetValueNames().Select(valueName => new { subkey = sk, valueName });
})
// But only the one that matches Blocked Senders
.FirstOrDefault(sk => valueNameBlocked == sk.valueName);
// If we got one, get the data from the values
if (match != null)
{
// Simultaneously setting subKey string for later while opening the registry key
using (var subkey = key.OpenSubKey(subKey = match.subkey))
{
blocked = Encoding.Unicode.GetString((byte[])subkey.GetValue(valueNameBlocked, emptyBytes));
safe = Encoding.Unicode.GetString((byte[])subkey.GetValue(valueNameSafe, emptyBytes));
}
}
}
// Remove empty items and the null-terminator (sometimes there is one, but not always)
Func<string, List<string>> cleanList = s => s.Split(semi, StringSplitOptions.RemoveEmptyEntries).Where(e => e != "\0").ToList();
// Convert strings to lists (dictionaries might be preferred)
var blockedList = cleanList(blocked).Dump("Blocked Senders");
var safeList = cleanList(safe).Dump("Safe Senders");
byte[] bytes;
// To convert a modified list back to a string for saving:
blocked = string.Join(";", blockedList) + ";\0";
bytes = Encoding.Unicode.GetBytes(blocked);
// Write to the registry
using (var key = Registry.CurrentUser.OpenSubKey(keyPath + '\\' + subKey, true))
key.SetValue(valueNameBlocked, bytes, RegistryValueKind.Binary);
// In LINQPad, this is what I used to view my binary data
string.Join("", bytes.Select(b => b.ToString("x2"))).Dump("Blocked Senders: binary data");
safe = string.Join(";", safeList) + ";\0"; bytes = Encoding.Unicode.GetBytes(safe);
string.Join("", bytes.Select(b => b.ToString("x2"))).Dump("Safe Senders: binary data");
答案 2 :(得分:0)
PST和IMAP4(ost)存储将列表保留在注册表的配置文件部分中。配置文件部分guid为 var img = new Image();
var mapCanvas = document.querySelector('.mapboxgl-canvas');
img.src = mapCanvas.toDataURL();
window.document.body.appendChild(img);
。要直接访问数据,您需要知道Outlook版本和配置文件名称。
Exchange存储将此数据保留为服务器端规则的一部分,该规则处理服务器端的传入消息。您可以在OutlookSpy中查看规则数据 - 转到收件箱文件夹,“关联内容”选项卡,找到名为(PR_RuleMsgName)==“垃圾邮件规则”的条目,双击它,看一看在PR_EXTENDED_RULE_CONDITION属性。
Outlook对象模型不会公开垃圾邮件设置。如果使用Redemption是一个选项,它会公开RDOJunkEmailOptions。TrustedSenders集合(适用于PST和Exchange存储):
{00020D0A-0000-0000-C000-000000000046}