【发布时间】:2020-05-17 04:46:45
【问题描述】:
我正在编写一个 VBScript 来从电子邮件中提取 CC。当我提取抄送时,它显示的不是电子邮件地址,而是此人的电子邮件名称。我在提取“来自”地址时遇到了同样的问题。我检查了来自该人的电子邮件地址类型(.SenderEmailType)是 SMTP 还是 EX,并且能够获取电子邮件地址而不是电子邮件名称。我不知道如何为 CC 做同样的事情。我在网上查过,它被写成循环通过“Mailitems.Recipent”。我是 vbscript 的新手,我不知道该怎么做。目前我正在使用 .CC 对象来获取 cc 详细信息。
Set Arg = WScript.Arguments
dim item1
dim objsubject
dim intcount
Dim i
dim savename
dim vTextFile
dim filename
dim extension
Dim t
Dim Itimestamp
dim savefolder
Dim vSenderEmailAddress
Dim vCcEmailAddress
Dim vFlagTextFileCreate
vFlagTextFileCreate = True
savefolder = "C:\Users\tgssupport\Documents\Automation Anywhere Files\Automation Anywhere\My Scripts\Retro Pricing\junk"
vTextFile = savefolder & "\File Report.txt"
vFlagExcelAttachmentFound = False
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then 'Could not get instance of Outlook, so create a new one
Err.Clear
Set olApp = CreateObject("Outlook.Application")
End If
on error goto 0
Set olns = olApp.GetNameSpace("MAPI")
olns.logon "Outlook",,False,True
'6 is for Inbox
Set objFolder = olns.GetDefaultFolder(6)
For each item1 in objFolder.Items
if item1.Unread=true then
objsubject = item1.subject
vCcEmailAddress = item1.CC
If item1.SenderEmailType = "SMTP" Then
vSenderEmailAddress = item1.SenderEmailAddress
ElseIf item1.SenderEmailType = "EX" Then
vSenderEmailAddress = item1.Sender.GetExchangeUser.PrimarySmtpAddress
End If 'If item1.SenderEmailType
msgbox vCcEmailAddress.
msgbox vSenderEmailAddress.
end if 'if item1.Unread=true
Next
olns.logoff
Set olns = Nothing
Set olApp = Nothing
WScript.Quit
【问题讨论】:
-
您好,如果您可以分享脚本的相关部分,将会很有帮助。
-
你好@arnonuem,我已经添加了代码。您可以看到变量 vCcEmailAddress 是我获取 cc 的变量。让我知道是否需要更多细节。感谢您的回复。
-
我不是这方面的专家,但我刚刚找到了这个解决方案:查看 Recipients 集合,并检查每个收件人对象的 type 属性。如果这有帮助,请尝试。我在这里找到了:forums.slipstick.com/threads/…
-
谢谢@arnonuem。我已经看到了,就像我之前提到的那样。我无法理解如何使用它。
-
请将那堵代码缩减为minimal reproducible example。