Link to home
Start Free TrialLog in
Avatar of Lyteck Lynhiavu
Lyteck LynhiavuFlag for United States of America

asked on

How to modify an incoming email but keep it in the inbox (for further processing)

Hello: is it possible to modify an incoming email and leave it sitting in the inbox (the email account is being monitored by another application... which will pick up the email and do further processing)

- if the item contains attachment.
       - code will append "--attachments--" to the subject
       - code will append "--attachments--" to the body

The code below is a starting point... however, I think there is a problem in that the code forwards a copy rather than replace the current copy in the inbox (for downstream processing by the application monitoring the inbox). Thanks, Lyteck

Sub ForwardEmail(Item As Outlook.MailItem)
    Dim olkForward As Outlook.MailItem, olkAttachment As Outlook.Attachment, strSubject As String, strRequester As String
        Set olkForward = Application.CreateItem(olMailItem)
        olkForward.HTMLBody = Item.HTMLBody
        If Item.Attachments.count > 0 Then
            olkForward.HTMLBody = olkForward.HTMLBody & "--attachments--"
        End If
        strSubject = Item.subject & "--attachments--"
        strRequester = item.from 'IS THIS CORRECT SYNTAX TO COPY THE ORIGINAL SENDER?
        olkForward.subject = strSubject
        olkForward.Recipients.Add strRequester
        olkForward.Recipients.ResolveAll
        olkForward.Send
    Set olkForward = Nothing
End Sub

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

When any mail comes into the inbox you want to append some text to the subject and body of the received mail and leave it otherwise unaffected ... is that correct?, because if so then I believe we can help.

Chris
Avatar of Lyteck Lynhiavu

ASKER

Yes,
- if email contains attachment, append text to subject and body
- if no attachment, leave email as is
In both cases the email sits in the inbox for further processing by other process.

Thanks Chris
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Chris. Apologies for the long delay. Lyteck