2016-06-17 8 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 둘 다 저에게 효과가 없습니다.

objOutlook.Session.Accounts.Item(0) 

는 내가이 같은에서 보내려는 계정을 찾기 위해 루프를 사용 :

답변

1

다음 코드는 첫 번째 이메일 주소를 당신이 Outlook에 연결되어있는 사용자를 줄 것이다는에 액세스 할 수 있습니다

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은 메일 항목에 사용중인 항목이 포함 된 사전 개체입니다. 메일 항목을 만들 때 Set oMailItem.SendUsingAccount = oOutlook.Session.Accounts.Item(iAccount)을 사용하여 보낸 계정을 지정합니다.