Mit VBA Email versenden aus 2. Postfach

  • Access

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von mumpel.

    Mit VBA Email versenden aus 2. Postfach

    Hallo,

    ich habe folgendes Problem. Ich konnte unter Access 2010 über Outlook 2010 eine Email aus Postfach Nummer 2 versenden mit dem Absender von Postfach 2. Nun nutze ich Outlook 2013 und habe das Problem, das immer vom Absender Postfach 1 versendet wird, egal was ich mache. Einzig, ich ändere das Standardpostfach hilft. Meine Frage ist daher, wurde was geändert in 2013? Es hilft auch nicht, das Konto zu definieren, oder die Mailadresse einzutragen.

    Jemand eine Idee?

    VB.NET-Quellcode

    1. Set DB = CurrentDb
    2. On Error Resume Next
    3. Dim OutlookApp As Object
    4. Set OutlookApp = GetObject(, "Outlook.Application")
    5. If Err <> 0 Then
    6. Shell "Outlook.exe"
    7. MsgBox "Bitte warten Sie bis Outlook gestartet ist.", vbOKOnly, "Information"
    8. Else
    9. End If
    10. Dim objApp As Outlook.Application
    11. Dim objNS As Outlook.NameSpace
    12. Dim objFolder As Outlook.MAPIFolder
    13. Dim objDummy As Outlook.MailItem
    14. Dim objRecip As Outlook.Recipient
    15. Dim objmail As Outlook.MailItem
    16. Dim strMsg As String
    17. Dim strName As String
    18. On Error Resume Next
    19. NachrichtText = Me.Body
    20. Set UserName = Me.frm_main_mail
    21. Set Computer = Me.frm_main_computername
    22. Set infektionsdatum = Me.frm_main_datum
    23. SubjectText = "Computervirenvorfall"
    24. strName = email@privat.de
    25. 'strName = "Text"
    26. Set objApp = CreateObject("Outlook.Application")
    27. Set objNS = objApp.GetNamespace("MAPI")
    28. Set objDummy = objApp.CreateItem(olMailItem)
    29. Set objRecip = objDummy.Recipients.Add(strName)
    30. objRecip.Resolve
    31. If objRecip.Resolved Then
    32. 'MsgBox "Bitte prüfen" & objRecip.Resolve, vbOKOnly, "Information"
    33. On Error Resume Next
    34. Set objFolder = objNS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderInbox)
    35. If Not objFolder Is Nothing Then
    36. Set objmail = objFolder.Items.Add
    37. With objmail
    38. .To = UserName
    39. .Subject = SubjectText
    40. .Attachments.Add "\\Virusvorfall.pdf"
    41. .HTMLBody = NachrichtText
    42. .HTMLBody = Replace(.HTMLBody, "%Computer%", Computer)
    43. .HTMLBody = Replace(.HTMLBody, "%infektionsdatum%", infektionsdatum)
    44. '.display
    45. .Send
    46. End With
    47. End If
    48. End If
    49. itemcount = itemcount + 1
    50. Me.frm_main_angeschrieben = Date
    51. On Error GoTo 0
    52. End If
    53. End If
    54. End If
    55. End If
    Hallo!

    petaod schrieb:


    [...] verwendet man SentOnBehalfOfName [...]

    Aber nur wenn man einen Exchange-Server hat. Ab Office 2007 kann man SendUsingAccount ( Set .SendUsingAccount = .Session.Accounts.Item("Kontoname") ) nutzen. Funktioniert aber nur wenn für jeden Emailadrresse eine eigene Ordnerstruktur (PST-Datei) existiert.

    Gruß, René