Emails an mehrere Adressen via Outlook versenden

  • VB.NET

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

    Emails an mehrere Adressen via Outlook versenden

    Moin!

    bisher habe ich mit folgendem Code immer eine E-Mail in Outlook generieren lassen - hat geklappt.

    VB.NET-Quellcode

    1. Public Sub OpenOutlook(BetreffZeile As String, Body As String, _AdressenEmail As String, Optional SendCC As Boolean = False)
    2. Dim objOutlook As Object
    3. Dim objOutlookMsg As Object
    4. Const olMailItem = 0
    5. 'Const olBCC = 3
    6. Const olImportanceHigh = 1
    7. Const olCC = 2
    8. Const olTo = 1
    9. Dim HowToAdress As Integer = olTo
    10. If SendCC = True Then HowToAdress = olCC
    11. Try
    12. objOutlook = CreateObject("Outlook.Application")
    13. objOutlookMsg = objOutlook.CreateItem(olMailItem)
    14. With objOutlookMsg
    15. Dim objOutlookRecip As Object = .Recipients.Add(_AdressenEmail)
    16. objOutlookRecip.type = HowToAdress
    17. .Subject = BetreffZeile
    18. .Body = Body
    19. .Importance = olImportanceHigh
    20. .Display() ' use .send() to send
    21. End With
    22. objOutlookMsg = Nothing
    23. objOutlook = Nothing
    24. Catch ex As Exception
    25. XMsgBox.ShowDialog("Leider ist ein Fehler bei der Erstellung der Email aufgetreten!" & vbCrLf & ex.ToString & vbCrLf &
    26. "EMail:=" & _AdressenEmail & Environment.NewLine &
    27. "Betreff:=" & BetreffZeile, _k_AppName, XMsgBoxButtons.OK, XMsgBoxIcon.Critical)
    28. End Try
    29. End Sub


    Nun wollte ich das auf mehrere ausweiten und als Parameter eine List Of String übergeben. Angepasst habe ich folgenden Bereich:

    VB.NET-Quellcode

    1. With objOutlookMsg
    2. Dim objOutlookRecip As Object
    3. For i As Integer = 0 To AdressenEmail.Count - 1
    4. objOutlookRecip = .Recipients.Add(AdressenEmail)
    5. Next
    6. objOutlookRecip.type = HowToAdress
    7. .Subject = BetreffZeile
    8. .Body = Body
    9. .Importance = olImportanceHigh
    10. .Display() ' use .send() to send
    11. End With


    Aber das funktioniert nicht - besser gesagt es wird der Abschnitt

    VB.NET-Quellcode

    1. objOutlookRecip.type = HowToAdress


    angemerkt.

    Kann mir einer weiterhelfen?

    Gruß Jan

    *Topic verschoben*

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()

    Zeile#2: Dim objOutlookRecip As Object: Object hat keine Property vom Typ type. Von welchem Typ ist objOutlookRecip tatsächlich?
    Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „VaporiZed“, mal wieder aus Grammatikgründen.

    Aufgrund spontaner Selbsteintrübung sind all meine Glaskugeln beim Hersteller. Lasst mich daher bitte nicht den Spekulatiusbackmodus wechseln.
    Ich stand auch vor dem Problem und habe mir folgende Sub dafür geschrieben:

    VB.NET-Quellcode

    1. ''' <summary>
    2. ''' Versendet eine Email mit Microsoft Outlook
    3. ''' Option Stict muss leider "OFF" bleiben wegen später Bindung
    4. ''' </summary>
    5. ''' <param name="an"></param>
    6. ''' <param name="cc"></param>
    7. ''' <param name="bcc"></param>
    8. ''' <param name="betreff"></param>
    9. ''' <param name="inhalt">Inhalt in Textform - Zeilenumbrüche werden automatisch durch BR ersetzt</param>
    10. ''' <param name="anhang">Stringarray mit Pfad- und Dateinamen</param>
    11. Public Sub NeueEmailMitOutlookVersenden(an As String, cc As String, bcc As String, betreff As String, inhalt As String, anhang() As String)
    12. Try
    13. Dim outlookapi As Object
    14. Dim outlookItem As Object
    15. outlookapi = CreateObject("Outlook.application")
    16. outlookItem = outlookapi.createitem(0)
    17. With outlookItem
    18. .Subject = betreff
    19. .To = an
    20. .cc = cc
    21. .bcc = bcc
    22. If inhalt <> "" Then .HTMLbody = inhalt.Replace(vbCrLf, "<br>")
    23. For i As Integer = 1 To 9
    24. If anhang(i) <> "" Then .Attachments.Add(anhang(i))
    25. Next
    26. .display
    27. End With
    28. outlookapi = Nothing
    29. outlookItem = Nothing
    30. Catch ex As Exception
    31. MessageBox.Show("Es scheint kein kompatibler Outlook Mailclient auf Ihrem Computer installiert zu sein.", "Microsoft Outlook nicht gefunden", MessageBoxButtons.OK, MessageBoxIcon.Stop)
    32. End Try
    33. End Sub
    Liebe Grüße
    Roland Berghöfer

    Meine aktuellen und kostenlos verwendbaren Tools (mit VB.NET erstellt): freeremarkabletools.com | priconman.com | SimpleCalendar | AudibleTouch | BOComponent.com | bonit.at