Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
realdata Absent Member.
Absent Member.
2515 views

Outlook 2007/2010: sendUsingAccount doesn't work

We want to set the account under which the mailitem is to be sent.

modify hMail, @SendUsingAccount, hAccount

But the command doesnt't work, the default account is used.


Example:
We have several accounts in Outlook and we want to use another account than the default -> notthedefault@xyz.com

This VB-Example works:
Private Sub Command1_Click()
    Dim oAccount As Outlook.account 'display all accounts
    For Each oAccount In Application.Session.Accounts
        MsgBox (oAccount.SmtpAddress)
    Next
    For Each oAccount In Application.Session.Accounts
        'send mail with another account, not with the default
        If oAccount.SmtpAddress = "notthedefault@xyz.com" Then
            Dim oMail As Outlook.MailItem
            Set oMail = Application.CreateItem(olMailItem)
             oMail.Subject = "VB: SendUsingAccount"
            oMail.Recipients.Add ("reciptient@zzz.com")
            oMail.Recipients.ResolveAll
            oMail.SendUsingAccount = oAccount
            oMail.Send
        End If
    Next
End Sub


But the Acu-Example doesn't work, the command SendUsingAccount is inefficient:
      *-----------------------------------------------------------------
       main section.
      *-----------------------------------------------------------------
       m-anfang.
           initialize hAppOutlooks.
           move zero to wh-ol-ind.
      *
           create application of outlook handle in hAppOutlook
      *
           modify hAppOutlook, @getnamespace("MAPI")
               giving hNameSpace
           inquire hNameSpace, @Accounts
               in hAccounts
           inquire hAccounts, @Count
               in wh-olkonten-anz
      *
           if wh-olkonten-anz > 1
      *    ---- display all accounts -> OK -----------------------------    
               perform varying wh-ol-ind from 1 by 1
                        until wh-ol-ind > wh-olkonten-anz
                   modify hAccounts, @item(wh-ol-ind)
                       giving hAccount
                   inquire hAccount, @SmtpAddress
                       in wh-olkonto-email
                   display message box wh-olkonto-email
                   destroy hAccount
               end-perform
      *    ---- use a not default account -> problem -------------------    
               perform varying wh-ol-ind from 1 by 1
                        until wh-ol-ind > wh-olkonten-anz
                   modify hAccounts, @item(wh-ol-ind)
                       giving hAccount
                   inquire hAccount, @SmtpAddress
                       in wh-olkonto-email
                   if wh-olkonto-email = "notthedefault@xyz.com"
                       display message box "Found:", wh-olkonto-email
                       modify hAppOutlook, @createitem(0)
                           giving hMail
                       modify hMail, @to, "reciptient@zzz.com"
                       modify hMail, @Subject, "Acu: SendUsingAccount"
      *    -----------------------this command doesn't work ------------
                       modify hMail, @SendUsingAccount, hAccount
      *    -------------------------------------------------------------
                       modify hMail, @send()
                       destroy hMail
                   end-if
                   destroy hAccount
               end-perform
           end-if.
           destroy hAccounts.
           destroy hNameSpace.
           destroy hAppOutlook.
       m-ausis.
           goback.

Who can help me?

 

0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert

RE: Outlook 2007/2010: sendUsingAccount doesn't work

I read a VB post suggesting using SendOnBehalfOfName

0 Likes
realdata Absent Member.
Absent Member.

RE: Outlook 2007/2010: sendUsingAccount doesn't work

Thank you for your feedback.

We know this option, but the account is still the default one, only the adress for the response is changed.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.