2

我在 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);
                }
            }
        }

因此,上述代码将所有电子邮件移至垃圾邮件,即使它们存在于安全发件人列表中。因此,我想获得安全的发件人列表,这样我就可以避免这种垃圾邮件检查。

有人可以帮我吗?

4

3 回答 3

1

The Outlook object model doesn't expose these lists (for more or less obvious reasons). The safe sender list can be read straight from the registry at:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\[PROFILE NAME]\0a0d020000000000c000000000000046\001f0418

This binary registry key contains double-byte characters, separated by a semicolon (;).

The MAPI property mapping onto this registry key is PR_SPAM_TRUSTED_SENDERS_W, documented here.

于 2011-06-06T19:00:09.053 回答
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");
于 2015-12-24T17:59:39.927 回答
0

PST 和 IMAP4 (ost) 存储将该列表保存在注册表的配置文件部分中。配置文件部分指南是{00020D0A-0000-0000-C000-000000000046}. 要直接访问数据,您需要知道 Outlook 版本和配置文件名称。

Exchange 存储将此数据保留为在服务器端处理传入消息的服务器端规则的一部分。您可以在OutlookSpy中查看规则数据 - 转到收件箱文件夹的“关联内容”选项卡,找到名为 (PR_RuleMsgName) == “垃圾邮件规则”的条目,双击它,查看 PR_EXTENDED_RULE_CONDITION 属性.

Outlook 对象模型不公开垃圾邮件设置。如果使用Redemption是一个选项,它会公开RDOJunkEmailOptions .TrustedSenders 集合(适用于 PST 和 Exchange 存储):

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Store = Session.Stores.DefaultStore
set TrustedSenders = Store.JunkEmailOptions.TrustedSenders
for each v in TrustedSenders
  debug.print v
next
于 2015-12-24T19:32:04.547 回答