惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
V
V2EX
博客园 - 【当耐特】
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
B
Blog
V
Visual Studio Blog
D
DataBreaches.Net
C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs

博客园 - 袁礼定

推荐网站: guship.cn 推荐网站: 开发测试教程 devqa.cn C#参考教程 http://www.csref.cn 最全的运营推广方案,教你如何从零开始运营APP SEO: Response.Redirect() 摘抄: Windows XP登录口令丢失的应急办法 随想 .net中统计时间的方法 zhaichao: 蔡文胜:站长之王 Sub String in Dos command Merge file using dos command Trip to America for 3 more months 明天的飞机,到美国培训和出差三个月,记一笔 javascript 游戏开发 乡村与城市的差别不是18年! 摘抄:透明PNG在IE6下的官方解决方案 本人从事软件技术开发也有多年,打算先尝试往外迈一步试试! 在办公室里面不能访问部分.cn域名的网站,但不在办公室里面就能访问 汉字转拼音缩写的函数(C#)
Get Sender Email Address from Outlook using CDO in C#
袁礼定 · 2007-06-07 · via 博客园 - 袁礼定

//Step 1: Add reference of  "Microsoft CDO 1.21 Library" and "Outlook"

private object oMissing = System.Reflection.Missing.Value;

public string GetFromAddress ( Outlook.MailItem msg )
  {
   string strReturn = string.Empty;

   MAPI.Session oSession = new MAPI.Session ( );
   oSession.Logon ( oMissing, oMissing, false, false, null, oMissing, oMissing );
   MAPI.Message oMessage = ( MAPI.Message ) oSession.GetMessage ( msg.EntryID,oMissing );

   MAPI.Fields fields = ( MAPI.Fields ) oMessage.Fields;
   MAPI.Field oFiled = ( MAPI.Field ) fields.get_Item ( MAPI.CdoPropTags.CdoPR_SENDER_EMAIL_ADDRESS, oMissing );

   strReturn = oFiled.Value.ToString ( );

   oSession.Logoff ( );

   return strReturn;  
  }

You can also use VBA as following:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Desc: Get the from address from of the specified MailItem
'Input:
'   objMsg: The object class can be Outlook.MailItem or MAPI.Message
'Output:
'   byte array
'Remarks:
'   Since there is no function to get from address in outlook, so we use this function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function GetFromAddress(objMsg)
   
    ' start CDO session
    Set objSession = CreateObject("MAPI.Session")
    objSession.Logon "", "", False, False
   
    ' pass message to CDO
    strEntryID = objMsg.EntryID
    strStoreID = objMsg.Parent.StoreID
    Set objCDOMSG = objSession.GetMessage(strEntryID, strStoreID)
   
    ' get sender address
    On Error Resume Next
    strAddress = objCDOMSG.Sender.Address
    If Err = &H80070005 Then
        'handle possible security patch error
        MsgBox "The Outlook E-mail and CDO Security Patches are " & _
            "apparently installed on this machine. " & _
            "You must response Yes to the prompt about " & _
            "accessing e-mail addresses if you want to " & _
            "get the From address.", vbExclamation, _
            "GetFromAddress"
    End If
   
    GetFromAddress = strAddress
   
    Set objCDOMSG = Nothing
    objSession.Logoff
    Set objSession = Nothing
End Function