Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Modify incoming email through Apple Script and Rule

The problem here is to write back the modified source to view pane i.e modify the currently viewed message.

This commented code will explain you what I am trying to achieve.


set urtext to string
    set fileContents to string
    tell application "Microsoft Outlook"
        set theMessage to item 1 of (get current messages)
        set urtext to source of theMessage
    end tell

    --write source to the file
    set newFile to "/Users/mymac/Desktop/newTest1.html"
    set eof of newFile to 0
    open for access newFile with write permission
    write urtext to newFile
    close access newFile

    --modifying the contents of the email
    do shell script "/Users/mymac/Documents/'Microsoft User Data'/'Outlook Script 
    Menu Items'/test.py"

    --read source from the file
    set theFile to "/Users/mymac/Desktop/output3.html"
    open for access theFile
    set fileContents to (read theFile)
    close access theFile

    --problem here..How to write the source to the existing viewed message in 
    -- the main window without duplications
    tell application "Microsoft Outlook"
        set the_messages to selection
        repeat with this_message in the_messages

            --the line below modifies the contents, but I get two incoming mail messages
            --[one modified and one unmodified]
            set theMessage to make incoming message with properties {source:fileContents}

            --the line below does not modify the source of the message in view pane,
            --Remains the same as original source
            --set fileContents to source of this_message 

        end repeat 
    end tell

MacBook Pro, Mac OS X (10.6.3)

Posted on Jul 15, 2011 12:26 PM

Reply
Question marked as Best reply

Posted on Jul 15, 2011 8:56 PM

I don't use/have Outlook, so I can't be definite here, but there are several glaring issues.


#1 :

--the line below modifies the contents, but I get two incoming mail messages

--[one modified and one unmodified]

set theMessage to make incoming message with properties {source:fileContents}


Of course you get two messages - you're telling Outlook to make incoming message so you're making a new message in addition to the existing one. Of course, making new incoming messages like this is completely bogus, but that's just another example of Office's awful AppleScript implementation.


--the line below does not modify the source of the message in view pane,

--Remains the same as original source

--set fileContents to source of this_message

I'll assume you're uncommenting the last line before running, but it's not surprising that it doesn't change the source of the message - you're not telling it to. You are creating a new variable called fileContents which contains the source of this_message.


I think what you're aiming for here is more along the lines of:


set source of this_message to fileContents


which tells AppleScript to set the source of this_message to the fileContents.

2 replies
Question marked as Best reply

Jul 15, 2011 8:56 PM in response to thinkcoolsa

I don't use/have Outlook, so I can't be definite here, but there are several glaring issues.


#1 :

--the line below modifies the contents, but I get two incoming mail messages

--[one modified and one unmodified]

set theMessage to make incoming message with properties {source:fileContents}


Of course you get two messages - you're telling Outlook to make incoming message so you're making a new message in addition to the existing one. Of course, making new incoming messages like this is completely bogus, but that's just another example of Office's awful AppleScript implementation.


--the line below does not modify the source of the message in view pane,

--Remains the same as original source

--set fileContents to source of this_message

I'll assume you're uncommenting the last line before running, but it's not surprising that it doesn't change the source of the message - you're not telling it to. You are creating a new variable called fileContents which contains the source of this_message.


I think what you're aiming for here is more along the lines of:


set source of this_message to fileContents


which tells AppleScript to set the source of this_message to the fileContents.

Modify incoming email through Apple Script and Rule

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.