欧非资源网:安全、免费、专业放心的资源下载站! 最新软件|软件分类

您的位置:欧非资源网 > 其他专区 > Outlook > outlook收件箱中发件人使用联系人

outlook收件箱中发件人使用联系人

时间:2021-12-24 22:50作者:admin来源:未知人气:386我要评论(0)

outlook有个特别不符合国人习惯的小问题:即使发件人已经添加到了联系人地址簿中,在收件箱中查看邮件列表时,发件人栏显示的依然是对方自定义的名字,整体看起来很杂乱。
百般查找也没找到设置方法和合适的插件。写了个宏脚本,暂时实现了替换收件箱中邮件列表发件人的功能。
最近工作忙,先凑合用着,以后有时间再完善人机交互方案。

使用方法
在outlook选项中使能开发工具页面,打开VB编辑开发窗口。添加新的模块,在模块的编辑界面贴入下面的代码。运行宏即可。

详细代码
代码中的write #1等是注释代码,可以都删掉。

函数1
函数updatesendername输入为收件箱中的没封邮件,函数功能是判断发件人类型是否是exchange,如果是,则可以获取到exchange通讯录中的信息,使用信息替换发件人名称(exchange通讯录类中的可用字段可以参考outlook vb的帮助文档)
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application

Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"

Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"

Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select

Set objApp = Nothing
End Function
Function mail_rename_sender(ByVal Item As Object, ByVal log As Boolean)

Dim myItem As Outlook.MailItem
Dim tmpPos As Integer
Dim tmpFlag As String
Set myItem = Item

If log Then
Write #1, '写入空白行。
Write #1, myItem.SenderEmailAddress, myItem.SentOnBehalfOfName, myItem.SenderEmailType, myItem.SenderName, myItem.SendUsingAccount, TypeName(myItem.sender)
End If

If myItem.SenderEmailType = "EX" Then
Dim oExUser As Outlook.ExchangeUser
Set oExUser = myItem.sender.GetExchangeUser
If log Then
Write #1, "11111", oExUser.Address, oExUser.PrimarySmtpAddress, oExUser.FirstName, oExUser.LastName, oExUser.Name
End If

If InStr(oExUser.OfficeLocation, "未来") <> 0 Then
tmpFlag = "$"
tmpPos = 10
Else
tmpPos = InStr(oExUser.OfficeLocation, "(")
'MsgBox (tmpPos)
If tmpPos = 0 Then
tmpPos = 11
Else
tmpPos = tmpPos - 1
End If
tmpFlag = "*"
End If
myItem.SentOnBehalfOfName = tmpFlag & " " & oExUser.LastName & "(" & oExUser.Alias & ")@" & "[" & Left(oExUser.OfficeLocation, tmpPos) & "]" '"-" & oExUser.CompanyName & "]"

Else
If TypeName(myItem.sender) = "AddressEntry" Then '发件人在联系人中
Set itemContact_temp = myItem.sender.GetContact()
If itemContact_temp Is Nothing Then
If log Then
Write #1, "77777777777777777777", myItem.Subject
End If
Else
If log Then
Write #1, "2222222", itemContact_temp.Email1Address
End If
myItem.SentOnBehalfOfName = "# " & itemContact_temp.FullName
End If
Else 'sender类型不是addressEntry时,意味着联系人中没有保存该发件人
Write #1, "666666666666", TypeName(myItem.sender)
End If
End If

myItem.Save

End Function

Sub mail_rename_sender_batch(ByVal num As Integer)

Dim oInbox As Outlook.Folder
Dim myItem As Outlook.MailItem
Dim myItems As Outlook.Items
Dim tmpCount As Integer

Open "G:TEMPoutlook.txt" For Output As #1
Write #1, "Hello World", 234 ' 写入以逗号隔开的数据。
Write #1, '写入空白行。

Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)

Set myItems = oInbox.Items
myItems.Sort "[SentOn]", True

tmpCount = myItems.Count
If (num > 0) And (num < tmpCount) Then
tmpCount = num
End If

'遍历所有邮件
For i = 1 To tmpCount 'oInbox.Items.Count

'If TypeName(oInbox.Items(i)) = "MailItem" Then

'Set myItem = oInbox.Items(i)
If TypeName(myItems(i)) = "MailItem" Then

Set myItem = myItems(i)

temp = mail_rename_sender(myItem, True)

End If

Next

Close #1 ' 关闭文件。


End Sub

 

函数2
update_folder是宏名(第一次折腾office中的vb,没搞懂概念,感觉sub xxx类似main函数,算是程序的主入口)点击运行宏就会从这里开始,函数中内容是获取到收件箱,并遍历收件箱中所有电子邮件(还有些会议通知神马的先不管),每封邮件调用updatesendername函数更新发件人名称。

Sub update_folder()
Dim myc As common
Set myc = New common
myc.mail_rename_sender_batch (-1)

End Sub

Private Sub Application_BeforeFolderSharingDialog(ByVal FolderToShare As MAPIFolder, Cancel As Boolean)

End Sub

Private Sub Application_ItemLoad(ByVal Item As Object)
Dim myc As common
Set myc = New common
Set myObj = myc.GetCurrentItem()
If TypeName(myObj) = "MailItem" Then
temp = myc.mail_rename_sender(myObj, False)
End If
End Sub

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
End Sub

Private Sub Application_MAPILogonComplete()

End Sub

Private Sub Application_NewMail()

'Dim myc As common
'Set myc = New common
'myc.mail_rename_sender_batch (3)

End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim myc As common
Set myc = New common
Dim vMail As Object
Set vMail = Application.Session.GetItemFromID(EntryIDCollection)
'MsgBox vMail.To & vbCrLf & vMail.CC & TypeName(vMail)

If TypeName(vMail) = "MailItem" Then
temp = myc.mail_rename_sender(vMail, False)
End If

End Sub

outlook收件箱中发件人使用联系人的下载地址:
  • 本地下载

  • 相关阅读 ​Outlook如何设置关闭时隐藏在任务栏右下角​Outlook如何自动接收邮件​Outlook如何终止发送邮件​Outlook如何设置后台自动发送和接收邮件​Outlook如何设置定时提醒​Outlook如何在主界面中显示邮件内容​Outlook如何在界面中显示待办事项Outlook如何将英文版的界面设置为中文版​Outlook如何设置退出时也能自动发送和接收邮件​Outlook中附件无法预览

    文章评论
    发表评论

    热门文章 Outlook邮箱注册入口_Outlook注册教程Outlook写邮件时如何快速插入表情符号Outlook 邮箱容量设置扩充教程Outlook如何设置日历与手机、电脑同步

    最新文章 ​Outlook如何设置关闭时隐藏在任务栏右下角​Outlook如何自动接收邮件 ​Outlook如何终止发送邮件​Outlook如何设置后台自动发送和接收邮件​Outlook如何设置定时提醒​Outlook如何在主界面中显示邮件内容

    人气排行 Outlook邮箱注册入口_Outlook注册教程Outlook写邮件时如何快速插入表情符号Outlook 邮箱容量设置扩充教程Outlook发送邮件一直停留在发件箱的解决办法Outlook如何设置日历与手机、电脑同步Outlook如何精准搜索邮件Outlook 2019如何配置163邮箱的完整图解实例教程Outlook 如何修改邮件发件人姓名名称

    盖楼回复X

    (您的评论需要经过审核才能显示)