MsOf07 remove "forwarded content" while replying to customer-VBForums
Results 1 to 7 of 7

Thread: remove "forwarded content" while replying to customer

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    remove "forwarded content" while replying to customer

    Dear all,

    I was wondering if there is a way to solve this problem through VBA.

    in my office I have the following situation:

    client send mail to our general first line mailbox if they can't handle this request they will forward this mail to the second line general mailbox. worst case senario the mail is forwarded to more departments before it's arriving at the second line.

    2nd line knows the solution to the problem of this client and want to reply to the client.
    if you click by default on the reply button you get the last senders email adres in the TO field which is very annoying since you have to search for the clients email adress first remove all the "useless forwarded content" and form your reply to the client.

    what would i like to achieve :

    1 retrieve the original email adres of the client
    2 remove all the "useless content" between the original mail and my reply
    3 change the reply email adres into the clients email adress
    4 move the original reply adres to the from field

    can someone help me out with this problem?
    concerning point 1 I found this function on the internet
    Code:
    Private Function GetOriginalFromEmail(posStartHeader As Integer, _
            posEndHeader As Integer, strBody As String) As String
        GetOriginalFromEmail = ""
        If (posStartHeader < posEndHeader And posStartHeader > 0) Then
            posStartHeader = posStartHeader + Len(START_MESSAGE_HEADER) + 1
            Dim posFrom As Integer
            posFrom = InStr(posStartHeader, strBody, FROM_MESSAGE_HEADER)
            If (posFrom < posStartHeader) Then
                Return
            End If
            posFrom = posFrom + Len(FROM_MESSAGE_HEADER)
            Dim posReturn As Integer
            posReturn = InStr(posFrom, strBody, Chr$(13))
            If (posReturn > posFrom) Then
                GetOriginalFromEmail = _
                    Mid(strBody, posFrom, posReturn - posFrom)
            End If
        End If
    End Function
    thanks

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: remove "forwarded content" while replying to customer

    can no one help me out with this?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,995

    Re: remove "forwarded content" while replying to customer

    i am sure it is possible, i have not had time to look a the forwarded message item object yet, maybe tonight
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: remove "forwarded content" while replying to customer

    westconn, that would be great thx

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,995

    Re: remove "forwarded content" while replying to customer

    i can easily get the original text and email address from the body, but it does not include all the images, i will have to look at it further for a satisfactory method to get the original appearance

    i am presently time poor
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: remove "forwarded content" while replying to customer

    Westconn,
    I don't need images as such just plain text is more then sufficient,

    the purpose is that I need to reply to the client with the original mail from the client and remove all forwarded and previous replies from other departments in order to give the client the Idea that his mail just has been treated by me and didn't pass 5 departments before I got the chance to reply to him.

    thanks again for helping me out here

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,995

    Re: remove "forwarded content" while replying to customer

    here is the sample i was working with
    Code:
    For Each msg In myFolder.Items
    If InStr(msg.Subject, "FW:") > 0 Then Stop: Exit For
    Next
    Dim m As MailItem
    
    Set m = msg
    strt = InStrRev(msg.Body, "Original Message")
    strt = InStr(strt, msg.Body, vbNewLine) + 2
    m.Body = Mid(msg.Body, strt)
    strt = InStr(m.Body, "=") + 1
    nd = InStr(strt, m.Body, "]")
    r = Mid(m.Body, strt, nd - strt)
    m.Recipients.Add r
    m.Subject = "this is a test"
    m.send
    you can get the original subject and remove the FW: or replace with RE:
    add your reply before the original body
    i am sure this can be improved on a lot
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.