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

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - 袁礼定

推荐网站: 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