Outlook에서 이메일을 전달하는 VBA

Outlook에서 이메일을 전달하는 VBA

받은 이메일을 전달할 수 있는 VBA를 만들려고 합니다. 유일한 문제는 내가 전달하려는 이메일의 제목이 다르다는 것입니다. 시작만 똑같습니다. 이것이 내가 얻은 정도입니다(ThisOutlookSession에 삽입해야 함). 누군가 나를 도와줄 수 있나요?

Public WithEvents objInbox As Outlook.Folder
Public WithEvents objInboxItems As Outlook.Items
Private Sub Application_Startup()
    Set objInbox = Outlook.Application.Session.GetDefaultFolder(olFolderInbox)
    Set objInboxItems = objInbox.Items
End Sub

Private Sub objInboxItems_ItemAdd(ByVal item As Object)
    Dim objMail As Outlook.MailItem
    Dim objForward As Outlook.MailItem

    If TypeOf item Is MailItem Then
       Set objMail = item

       'If it is a specific new email'
       If (objMail.Subject = "Offer Response Received") Then



           Set objForward = objMail.Forward
           'Customize the forward subject, body and recipients'
           With objForward
                .Subject = "Offer accepted"
                .HTMLBody = "<HTML><BODY>Please proceed. </BODY></HTML>" & objForward.HTMLBody
                .Recipients.Add ("")
                .Recipients.Add ("")
                .Recipients.ResolveAll
                .Importance = olImportanceHigh
                .Send
           End With
       End If
    End If
End Sub

답변1

해당 메일의 공통 본문 내용을 제목으로 확인하실 수 있습니다.

Private Sub objInboxItems_ItemAdd(ByVal item As Object)

    Dim objMail As MailItem
    Dim objForward As MailItem

    Dim beginStr As String
    Dim lenBegin As Long

    beginStr = "the common text at beginning of applicable mail"
    lenBegin = Len(beginStr)

    If TypeOf item Is MailItem Then

        Set objMail = item

        'New email where the "beginning is the same"
        If Left(objMail.Subject, lenBegin) = beginStr Then

            Set objForward = objMail.Forward

            'Customize the forward subject, body and recipients'
            With objForward
                .Subject = "Offer accepted"
                .HTMLBody = "<HTML><BODY>Please proceed. </BODY></HTML>" & objForward.HTMLBody
                '.recipients.Add ("")
                '.recipients.Add ("")
                .recipients.ResolveAll
                .Importance = olImportanceHigh
                .Display    '.Send
            End With

        End If
    End If

End Sub

관련 정보