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.
Vielen Dank
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
- Option Explicit
- <!--#include file="%PRJDIR%\script\CosmoOle.vbs"-->
- 'Sub SendEmail()
- 'MsgBox "Test1"
- ' This macro sends an email from any account in Outlook.
- ' It checks Outlook for the identifying domain of the desired account
- ' and selects it as the From account.
- '***************************************************************************************************
- '***** Send an Email Using One of Several Accounts in Outlook
- '***************************************************************************************************
- '***** Define objects
- Dim i
- Dim Acct_Num
- Dim objBkm
- Dim objDoc
- Dim sSubj
- Dim sMsg
- 'MsgBox "Test2"
- '***** Define distribution list aliases (add as many as necessary).
- Dim oaccountName
- 'oaccountName = "info@vision4d.de"
- oaccountName = "info@eberle-systeme.de"
- MsgBox oaccountName, vbOKOnly, "oaccountName"
- '***** Create the email
- Dim oOutApp
- Set oOutApp = CreateObject("Outlook.Application")
- Dim oOutMail
- Set oOutMail = oOutApp.CreateItem(0)
- Set objDoc = oOutMail.GetInspector.WordEditor
- Set objBkm = objDoc.Bookmarks("_MailAutoSig")
- '***** Get desired account's Outlook Account Number
- Dim OutApp
- Set OutApp = CreateObject("Outlook.Application")
- 'DIM index
- 'For index = 1 To 3
- ' MsgBox index
- ' Next
- ' Ensure the length value of the Right() function is correct
- ' for the test string to find the desired account
- MsgBox "Test3"
- For i = 1 To OutApp.Session.Accounts.count
- 'Test auf Nummer des Outlook account
- If Right(OutApp.Session.Accounts.Item(i), 16) = oaccountName Then
- Acct_Num = i
- MsgBox i,vbOKOnly,"OutApp.Session.Accounts.Item"
- END If
- MsgBox i,vbOKOnly,"OutApp.Session.Accounts.count"
- Next
- '***** Create the email subject line
- sSubj = "Insert subject line here"
- '***** Create the message for the email body using HTML tags if desired
- sMsg = "<font face=""Arial""><font size=2><font color=""rgb(89,102,122)"">" & _
- "Insert message here</font></font></font>"
- MsgBox i,vbOKOnly,"Test4"
- Dim accountNumber
- For i = 1 to OutApp.Session.Accounts.count
- accountNumber = i
- MsgBox accountNumber,vbOKOnly,"accountNumber"
- Next
- '***** Populate the email fields and send it
- On Error Resume Next
- With oOutMail
- Set .SendUsingAccount = oOutApp.Session.Accounts.Item(2)
- ' Add recipients as necessary
- .Recipients.Add "info@vision4d.de"
- .Subject = sSubj
- .HTMLBody = sMsg & .HTMLBody
- ' Add attachments as necessary
- '.Attachments.Add ("C:\temp\Chart1.png")
- '.Attachments.Add ("C:\temp\Chart2.png")
- .Send ' Sends email immediately
- .Display ' Allows the email to be reviewed before sending
- End With
- On Error GoTo 0
- '***** Close the Outlook connections
- Set oOutMail = Nothing
- Set oOutApp = Nothing
- '***************************************************************************************************
- 'End Sub
Vielen Dank