使用VB脚本从Outlook中的特定地址获取未读电子邮件

时间:2013-05-08 14:13:31

标签: vbscript outlook

我想获取来自特定发件人的未读邮件的电子邮件地址。我尝试了以下代码,但它无法正常工作

Set olApp=CreateObject("Outlook.Application")
Set olMAPI=olApp.GetNameSpace("MAPI") 
Set oFolder = olMAPI.GetDefaultFolder(6)
Set allEmails = oFolder.Items

For Each email In oFolder.Items


If email.Unread = True Then
If email.SenderEmailAddress="Kalyanam.Raghuram@xxxx.com" Then

MsgBox email.Subject


End If
End If
Next

所以我检查了什么'email.SenderEmailAddress'正在通过插入此代码进行验证

For Each email In oFolder.Items

If email.Unread = True Then

MsgBox email.Subject
MsgBox email.SenderEmailAddress


End If
Next

它给了我一些无法理解但可读的输出。请让我知道任何解决方案。

2 个答案:

答案 0 :(得分:0)

您发布的代码为我工作,我在使用Outlook 2007的Windows Vista上

我要改变的一件事就是这个


        If LCase(email.SenderEmailAddress) = LCase("Kalyanam.Raghuram@xxxx.com") Then
          wscript.echo email.Subject
        End If

答案 1 :(得分:0)

Dio你的意思是你得到了一个EX类型的地址而不是预期的SMTP?

你看过_ExchangeUser.PrimarySmtpAddress吗? 在您的情况下,您可以使用MailItem.Sender.GetExchangeUser.PrimarySmtpAddress。准备好处理空值,因为每个值都可以为空。