Welche Nummer hat das Emailkonto xxx in meinem Outlook

  • VBScript

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von Marcus Gräfe.

    Welche Nummer hat das Emailkonto xxx in meinem Outlook

    Hallo zusammen,

    Ich habe mehrere Mailkonten und möchte abhänig vom sendenden Programm das eine, oder das andere Mailkonto verwenden.
    Aktuell muss ich immer wenn Outlook sich öffnet das entsprechen Mailkonto auswählen.
    Das nerft mich aber total.

    Ich habe bereits mir einiges zusammengebaut.
    Ich weiß auch (per Hand herausgefunden) dass es sich um die
    .SendUsingAccount = oOutApp.Session.Accounts.Item(x) handelt.

    Nun zu meiner Frage:
    Ich brauche eine Abfrage in der ich herrausfinde welches "x" zur Mailadress "sample@sample.de" gehört.
    In der Abfrage ab Zeile 66 ermittle ich schon die Anzahl der Konten die im Outlook angelegt sind.

    Die Frage ist nur: Welche Kontonummer gehört zu der Mailadresse "sample@sample.de"

    Hier mein Code den ich zusammengebatelt habe.

    Visual Basic-Quellcode

    1. Option Explicit
    2. <!--#include file="%PRJDIR%\script\CosmoOle.vbs"-->
    3. 'Sub SendEmail()
    4. 'MsgBox "Test1"
    5. ' This macro sends an email from any account in Outlook.
    6. ' It checks Outlook for the identifying domain of the desired account
    7. ' and selects it as the From account.
    8. '***************************************************************************************************
    9. '***** Send an Email Using One of Several Accounts in Outlook
    10. '***************************************************************************************************
    11. '***** Define objects
    12. Dim i
    13. Dim Acct_Num
    14. Dim objBkm
    15. Dim objDoc
    16. Dim sSubj
    17. Dim sMsg
    18. 'MsgBox "Test2"
    19. '***** Define distribution list aliases (add as many as necessary).
    20. Dim oaccountName
    21. 'oaccountName = "info@vision4d.de"
    22. oaccountName = "info@eberle-systeme.de"
    23. MsgBox oaccountName, vbOKOnly, "oaccountName"
    24. '***** Create the email
    25. Dim oOutApp
    26. Set oOutApp = CreateObject("Outlook.Application")
    27. Dim oOutMail
    28. Set oOutMail = oOutApp.CreateItem(0)
    29. Set objDoc = oOutMail.GetInspector.WordEditor
    30. Set objBkm = objDoc.Bookmarks("_MailAutoSig")
    31. '***** Get desired account's Outlook Account Number
    32. Dim OutApp
    33. Set OutApp = CreateObject("Outlook.Application")
    34. 'DIM index
    35. 'For index = 1 To 3
    36. ' MsgBox index
    37. ' Next
    38. ' Ensure the length value of the Right() function is correct
    39. ' for the test string to find the desired account
    40. MsgBox "Test3"
    41. For i = 1 To OutApp.Session.Accounts.count
    42. 'Test auf Nummer des Outlook account
    43. If Right(OutApp.Session.Accounts.Item(i), 16) = oaccountName Then
    44. Acct_Num = i
    45. MsgBox i,vbOKOnly,"OutApp.Session.Accounts.Item"
    46. END If
    47. MsgBox i,vbOKOnly,"OutApp.Session.Accounts.count"
    48. Next
    49. '***** Create the email subject line
    50. sSubj = "Insert subject line here"
    51. '***** Create the message for the email body using HTML tags if desired
    52. sMsg = "<font face=""Arial""><font size=2><font color=""rgb(89,102,122)"">" & _
    53. "Insert message here</font></font></font>"
    54. MsgBox i,vbOKOnly,"Test4"
    55. Dim accountNumber
    56. For i = 1 to OutApp.Session.Accounts.count
    57. accountNumber = i
    58. MsgBox accountNumber,vbOKOnly,"accountNumber"
    59. Next
    60. '***** Populate the email fields and send it
    61. On Error Resume Next
    62. With oOutMail
    63. Set .SendUsingAccount = oOutApp.Session.Accounts.Item(2)
    64. ' Add recipients as necessary
    65. .Recipients.Add "info@vision4d.de"
    66. .Subject = sSubj
    67. .HTMLBody = sMsg & .HTMLBody
    68. ' Add attachments as necessary
    69. '.Attachments.Add ("C:\temp\Chart1.png")
    70. '.Attachments.Add ("C:\temp\Chart2.png")
    71. .Send ' Sends email immediately
    72. .Display ' Allows the email to be reviewed before sending
    73. End With
    74. On Error GoTo 0
    75. '***** Close the Outlook connections
    76. Set oOutMail = Nothing
    77. Set oOutApp = Nothing
    78. '***************************************************************************************************
    79. 'End Sub


    Vielen Dank
    Danke für die schnelle Antwort.

    Leider tut das aber nicht was ich will.

    Zur Vertiefung:
    Ich habe meghrere Mailkonten und ich muss herrausfinden welche Nummer das Mailkonto info@eberle-systeme.de hat.
    Dies kann bei meinem Kolegen anders sein.
    Desswegen die Abfrage.
    Leider liefer mir die Abfrage nicht die Nummer "2"

    Hier meine Outlook-Kontoeinstellungen:
    (1) info@vision4d.de (Standard)
    (2) info@eberle-systeme.de
    (3) xxx@xxx.de
    (4) yyy@xxx.de

    Nochmal die Frage:
    wie kriege ich die Nummer von info@eberle-systeme.de herraus.

    vielen Dank

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Kissling“ ()

    Das Problem ist vmtl. das Right([...], 16), d. h. die feste Breite von 16. Warum hier überhaupt mit Right arbeiten? Geht nicht auch If OutApp.Session.Accounts.Item(i) = oaccountName?

    Falls doch unbedingt Right benutzt werden muss, weil im Item mehr als nur die reine Adresse drin steht, so muss es was in der Art sein: If Right(OutApp.Session.Accounts.Item(i), Len(oaccountName)) = oaccountName
    Besucht auch mein anderes Forum:
    Das Amateurfilm-Forum