2016-06-17 5 views
0

QTP Outlookオブジェクトモデルを使用して電子メールを送信しています。QTP、メーラーアドレスを送信

ここにコードがあります。

今、私は環境変数に送信者の電子メールアドレス&店にそれを取得するために必要な
'Create an object of type Outlook 
    Set objOutlook = CreateObject("Outlook.Application") 
    Set myMail = objOutlook.CreateItem(0) 

'Set the email properties 
    myMail.To = "[email protected]" 
    myMail.CC = "[email protected]; [email protected]" '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.SenderまたはmyMail.sendermailaddres両方とも私を働かせていません。

答えて

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)を使用して、送信するアカウントを指定します。