【问题标题】:QTP, send mailer addressQTP,发送邮件地址
【发布时间】:2016-10-18 21:00:55
【问题描述】:

我正在使用 QTP Outlook 对象模型发送电子邮件。

这是一段代码。

'Create an object of type Outlook
   Set objOutlook = CreateObject("Outlook.Application")
   Set myMail = objOutlook.CreateItem(0)

'Set the email properties
   myMail.To = "some_mail_id@gmail.com"
   myMail.CC = "some_mail_id_2@gmail.com; some_other_mail@yahoo.com" 'Sending mails to multiple ids
   myMail.BCC = "" 'If BCC is not required, then this line can be omitted
   myMail.Subject = "Sending mail from MS Outlook using QTP"
   myMail.Body= "Test Mail Contents"
   myMail.Attachments.Add("D:\Attachment.txt") 'Path of the file to be attached

'Send the mail
   myMail.Send

现在我需要检索发件人电子邮件地址并将其存储在环境变量中。 myMail.SendermyMail.sendermailaddres 他们都对我不起作用。

【问题讨论】:

    标签: vba email outlook send qtp


    【解决方案1】:

    以下代码将为您提供您连接到 Outlook 的用户可以访问的第一个电子邮件地址:

    objOutlook.Session.Accounts.Item(0)
    

    我使用循环来查找我要发送的帐户,如下所示:

    iAccount = 0
    For iLoop = 1 To oOutlook.Session.Accounts.Count
        If UCase(Trim(oOutlook.Session.Accounts.Item(iLoop))) = UCase(Trim(EmailData("SendFrom"))) Then
            iAccount = iLoop
            Exit For
        End If
    Next
    

    EmailData 是一个 Dictionary 对象,其中包含我用于邮件项目的项目。创建邮件时,我使用Set oMailItem.SendUsingAccount = oOutlook.Session.Accounts.Item(iAccount) 指定发送邮件的帐户。

    【讨论】:

      猜你喜欢
      • 2016-09-03
      • 2017-04-14
      • 1970-01-01
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 2014-04-11
      相关资源
      最近更新 更多