简体   繁体   中英

Forward email by subject edit body

I want to forward every mail with a specific subject to an e-mail. To the content of the original mail, a specific content ("geprüft") should be added. I have the code now, but it doesn't work properly. It sends the last E-Mail clicked on :(.

    Sub Test(oMail As MailItem) Dim MyItem As Outlook.MailItem Dim obj_curitem As MailItem Dim obj_newitem Dim obj_Selection Dim obj_curfolder Dim obj_msgitems Dim Forward As Object

If Err.Number = 0 Then
    Set obj_Selection = Outlook.ActiveExplorer.Selection
        If obj_Selection.Count > 0 Then

        For Each obj_curitem In obj_Selection
            strID = obj_curitem.EntryID
            Set olNS = Application.GetNamespace("MAPI")

            'Object auf einem neuen Item erstellen
            Set obj_newitem = obj_curitem.Forward
            With obj_curitem.Forward
                .Forward = True
                .SentOnBehalfOfName = "###"  'Deine Mailadresse
                .Subject = "WG" & .Subject                      'Betreff
                .To = "###"                    'Empfängermail
                .BODY = "geprüft" & .BODY                       'E-Mail Inhalt
                .Send

            End With
        Next
    End If End If End Sub

This loop works fine for me:

Dim tmpMail As MailItem

For Each tmpMail In ActiveExplorer.Selection

    Debug.Print tmpMail.Subject

    With tmpMail.Forward

        .Forward = True
        .SentOnBehalfOfName = "###"
        '.Subject = "WG" & .Subject 'WG is automatically added when forwarding
        .To = "###"
        .Body = "geprüft" & Chr(10) & .Body

        .Send
    End With
Next tmpMail

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM