我对Outlook 2007的富文本字段有疑问。我尝试在"收件人,密送,抄送字段" 中读取值(电子邮件地址)。我已经知道问题已知并且您只能在保存Outlook中的mailItem时读取字段。 所以,我尝试使用窗口处理程序和SendMessage函数访问电子邮件地址。但它只会返回:
{\ RTF1 \ ANSI \ ansicpg1252 \ deff0 \ deflang1031 {\ fonttbl {\ F0 \ fswiss \ fprq2 \ fcharset0 Tahoma;}} {* \ generator Riched20 12.0.6606.1000;} \ viewkind4 \ uc1 \ PARD \ F0 \ fs17 {\ PICT \ wmetafile0
因此,我认为Outlook使用嵌入对象替换电子邮件地址,此对象显示电子邮件地址。任何人都可以帮忙告诉我如何访问该对象并获取电子邮件地址吗?
答案 0 :(得分:0)
使用MailItem.Recipients集合 - 它将始终填充。
答案 1 :(得分:0)
我知道这一点,但在Outlook 2007中存在错误或缺少功能。从“到”字段中删除(电子邮件地址)收件人时,mailItem不会刷新其收件人集合。只有在添加并解决收件人时才会刷新!
所以我看到的唯一方法是阅读To-Field的内容是..通过SendMessage。
private int EditStreamProc(MemoryStream dwCookie, IntPtr pbBuff, int cb, out int pcb)
{
pcb = cb;
byte[] buffer = new byte[cb];
Marshal.Copy(pbBuff, buffer, 0, cb);
dwCookie.Write(buffer, 0, cb);
return 0;
}
private delegate int EditStreamCallback(MemoryStream dwCookie, IntPtr pbBuff, int cb, out int pcb);
[StructLayout(LayoutKind.Sequential)]
private struct EDITSTREAM
{
public MemoryStream dwCookie;
public int dwError;
public EditStreamCallback pfnCallback;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hwnd, uint msg, uint wParam, ref EDITSTREAM lParam);
private const int WM_USER = 0x0400;
private const int SF_RTF =3;
private const int EM_STREAMOUT = WM_USER + 74;
public string ReadRTFContentInOL2007(IntPtr handle)
{
string result = String.Empty;
using (System.IO.MemoryStream stream = new MemoryStream())
{
EDITSTREAM editStream = new EDITSTREAM();
editStream.pfnCallback = new EditStreamCallback(EditStreamProc);
editStream.dwCookie = stream;
SendMessage(handle, EM_STREAMOUT, SF_RTF, ref editStream);
stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{
result = reader.ReadToEnd();
}
}
return result;
}
当电子邮件地址解析后,我会收到:
{\ rtf1 \ ansi \ ansicpg1252 \ deff0 \ deflang1031 {\ fonttbl {\ f0 \ fswiss \ fprq2 \ fcharset0 Tahoma;}} {* \ generator Riched20 12.0.6606.1000;} \ viewkind4 \ uc1 \ pard \ f0 \ fs17 {\ PICT \ wmetafile0
所以Outlook用对象替换纯文本,我需要接收RTF内容的所有信息!我认为此内容中的某处必须是电子邮件地址。 To-Field Class是:RichEdit20WPT