如何从Outlook里获得用户的名字和头像

本文介绍了一种从Outlook中通过指定域名和别名获取联系人的缩略图及全名的方法。该方法利用了DirectorySearcher进行LDAP搜索,并从搜索结果中解析出所需的图像数据和姓名。

今天share一下如何从outlook里获得缩略图和全名的两个方法。方法的难点是如何从SearchResult 里获得想要的信息。因为这个结果里有大量信息。目前我还没有找到一个很好的方法来处理。找到后我会补全这块的信息。方法仅供参考。

        private static string GetThumnailImage(string domain, string alias)
        {
            Bitmap thumnailImage = null;
            DirectorySearcher dirSearcher = new DirectorySearcher();
            DirectoryEntry rootEntry = new DirectoryEntry("LDAP://fareast.corp.microsoft.com");
            dirSearcher.SearchRoot = rootEntry;
            dirSearcher.Filter = string.Format("(|(sAMAccountName={0})(cn={0}))", alias);
            dirSearcher.SearchScope = SearchScope.Subtree;
 
            SearchResultCollection searchResultColl = dirSearcher.FindAll();
            string imagePath = AppDomain.CurrentDomain.BaseDirectory + "thumbnailphoto.png";
            if (searchResultColl.Count <= 0)
            {
                throw new System.Security.Authentication.AuthenticationException();
            }
            SearchResult result = searchResultColl[0];
            if (result == null || result.Properties == null)
            {
                throw new System.Security.Authentication.AuthenticationException();
            }
            if (result.Properties["thumbnailphoto"] != null && result.Properties["thumbnailphoto"].Count > 0)
            {
                byte[] imageBytes = new byte[((byte[])result.Properties["thumbnailphoto"][0]).Count<byte>()];
                Array.Copy((byte[])result.Properties["thumbnailphoto"][0], imageBytes, imageBytes.Count<byte>());
                using (System.IO.MemoryStream mmStream = new System.IO.MemoryStream(imageBytes))
                {
                    thumnailImage = new System.Drawing.Bitmap(mmStream);
                    mmStream.Flush();
                    thumnailImage.Save(imagePath);
                }
            }
 
            return imagePath;
        }
 
        private static string GetFullName(string domain, string alias)
        {
            DirectorySearcher dirSearcher = new DirectorySearcher();
            DirectoryEntry rootEntry = new DirectoryEntry("LDAP://fareast.corp.microsoft.com");
            dirSearcher.SearchRoot = rootEntry;
            dirSearcher.Filter = string.Format("(|(sAMAccountName={0})(cn={0}))", alias);
            dirSearcher.SearchScope = SearchScope.Subtree;
 
            SearchResultCollection searchResultColl = dirSearcher.FindAll();
 
            string name = string.Empty;
            if (searchResultColl.Count <= 0)
            {
                throw new System.Security.Authentication.AuthenticationException();
            }
            SearchResult result = searchResultColl[0];
            if (result == null || result.Properties == null)
            {
                throw new System.Security.Authentication.AuthenticationException();
            }
            if (result.Properties["givenname"] != null && result.Properties["givenname"].Count > 0)
            {
                name = result.Properties["givenname"][0].ToString();
            }
            if (result.Properties["sn"] != null && result.Properties["sn"].Count > 0)
            {
                name += " " + result.Properties["sn"][0].ToString();
            }
 
 
            return name;
        }

<think>嗯,用户的问题是关于如何在Outlook中更改发送邮件时显示的头像。首先,我需要确认用户使用的Outlook版本,因为不同版本的操作步骤可能不同。但通常来说,Outlook头像设置与Microsoft账户或Exchange账户头像相关联。用户可能需要通过更改账户中的个人资料图片来实现。根据引用[1]中的信息,用户可能已经知道如何设置可信发件人的图片显示,但头像设置可能不同。引用[2][3]提到通过Python或PHP处理邮件,但用户的问题更偏向于客户端设置,所以可能需要指导用户进入账户选项修改头像。 步骤可能包括:打开Outlook,进入文件>账户设置,选择账户并更改图片。另外,如果用户使用Microsoft365,可能需要通过Office账户设置同步头像。需要提醒用户,更改后可能需要重启Outlook或等待同步生效。同时,确保图片符合尺寸格式要求,比如JPEG或PNG,建议正方形以避免变形。 可能还需要考虑缓存问题,如果头像没有立即更新,可能需要清除缓存或重新登录。此外,如果用户使用Exchange服务器,可能需要联系管理员更改,尤其是在企业环境中。需要分步骤说明,确保用户能够逐步操作,避免遗漏关键点。</think>### 如何在Outlook中更改发送邮件时显示的头像? 1. **通过Microsoft账户同步头像** - 登录网页版Microsoft账户(https://account.microsoft.com/) - 点击 **你的信息** > **编辑头像**,上传新图片并保存 - 重启Outlook客户端,新头像会通过云端同步显示在发件人信息中[^1][^2]。 2. **直接在Outlook客户端设置** - 打开Outlook,点击 **文件** > **账户设置** > **账户设置** - 双击需要修改的邮箱账户,选择 **更改** - 点击 **用户信息** 区域的 **图片** 按钮,上传本地图片 - 保存后发送测试邮件验证效果[^1]。 3. **企业Exchange账户的特殊情况** - 若使用公司Exchange服务器,请联系IT管理员,通过Active Directory修改全局头像设置[^2]。 ```plaintext 注意事项: 1. 图片建议尺寸为648×648像素,格式为PNG/JPG 2. 部分企业邮箱需等待24小时同步 3. 收件方客户端可能缓存旧头像,可尝试清除缓存 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值