使用vbscript提取电子邮件地址而不是抄送的电子邮件名称?

时间:2019-07-03 08:49:41

标签: vba vbscript

我正在编写一个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

2 个答案:

答案 0 :(得分:1)

With item1.Recipients
    For i = 1 To .Count
        If .Item(i).Type = OlMailRecipientType.olCC Then
            vCcEmailAddress = .Item(i).Address
            Exit For
        End If
    Next i
End With

答案 1 :(得分:-1)

Set objFolder = olns.GetDefaultFolder(6)
For each item1 in objFolder.Items      
   For Each RecipientObject In item1.Recipients
      If RecipientObject.Type = 2 Then
      msgbox RecipientObject.Address
      End if
   Next
Next