Exchange 2003/2007 have the Sender Filter feature.
How to retrieve sender e-mail addresses from outlook inbox?
I configure POP3 client with an account and its password remembered. This is the only profile in the outlook.
Using the Visual Studio 2008 to develop the program, the following is the C# code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection; // to use Missing.Value
//
You must add the COM reference Microsoft Outlook 11.0 for Outlook 2003 clientusing Outlook = Microsoft.Office.Interop.Outlook;namespace SendAddress
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
try
{
string path =
@"c:\MyTest.txt";
// Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
}
FileStream fs = File.Create(path);
string path1 = @"c:\myTest1.txt";
if (File.Exists(path1))
{
File.Delete(path1);
}
FileStream fs1 = File.Create(path1);
// Create the Outlook application.
// in-line initialization
Outlook.Application oApp = new Outlook.Application();
// Get the MAPI namespace.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using the default profile or existing session (no dialog box).
oNS.Logon(Missing.Value, Missing.Value, false, true);
//Get the Inbox folder.
Outlook.MAPIFolder oInbox = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
//Get the Items collection in the Inbox folder.
Outlook.Items oItems = oInbox.Items;
long ii = oItems.Count;
for (long i = ii; i>=1; --i)
{
Outlook.MailItem mItem = (Outlook.MailItem)oItems[i];
System.DateTime dt = this.dateTimePicker1.Value;
dt = dt.AddHours(-12);
if (mItem.ReceivedTime <= dt) break; AddText(fs, mItem.SenderEmailAddress); AddText(fs, "\r\n"); AddText(fs1, mItem.ReceivedTime.ToString()); AddText(fs1, "\r\n"); } oNS.Logoff(); //Explicitly release objects. oItems = null; oInbox = null; oNS = null; oApp = null; } //Error handler. catch (Exception e1) { Console.WriteLine("{0} Exception caught: ", e1); } // Return value. //return 0; Application.Exit(); } private static void AddText(FileStream fs, string value) {
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
}
===
open the
c:\mytest.txt file in Notepad.exe
Replace all
@ with
%@and save the file;
Open EXCEL;
Import data from c:\mytest.txt file with the separator
%replace
@ with
msExchTurfListNames: *@Pay attention to the space between msExchTurfListNames: and *Only keep the column with msExchTurfListNames:
*@xxx.comexport the sheet to a file: senderAddress.ldf
Open the senderAddress.ldf with Notepad.exe and modify it. The following is a example:
dn: CN=Default Message Filter,CN=Message Delivery,CN=Global settings,CN=Itsme,CN=Microsoft
Exchange,CN=Services,CN=Configuration,DC=itsme,DC=com
changetype: modifyadd: msExchTurfListNamesmsExchTurfListNames:
*@fhdf.commsExchTurfListNames:
*@56.commsExchTurfListNames:
*@jake.commsExchTurfListNames:
*@what.com-
=====
Pay attention to the dash (-) and the empty line must follow the dash in your senderAddress.ldf file.
=====
At exchange 2003 server:
ldifde -i -f c:\senderAddress.ldf
===
If the domain address is already contained in the msExchTurfListNames attribute, the import will fail.