Setting the content of an outgoing message fails - email

i tried to create an auto reply script but as soon as i try to set the content of the outgoing message it throws an error and tells me that "content" can't be read.
set replyMessage to reply thisMessage with opening window
delay 2
set rich text content of replyMessage to "Hallo"
any ideas?
edit: full code:
tell application "Mail"
set replyList to {}
set inboxMessages to every message in inbox
# get Einsatz mail from all emails
repeat with thisMessage in inboxMessages
set thisContent to content of thisMessage
set thisSender to sender of thisMessage
if thisSender contains "#pos-lifestyle.de" then
if thisContent contains "nochmal alle wichtigen Informationen zum Heimspiel" then
if thisContent contains "deinen Einsatz per Mail" and thisContent contains "Bitte bestätige" then
set end of replyList to thisMessage
set read status of thisMessage to true
end if
end if
end if
end repeat
# reply to all Einsatz mails
repeat with thisMessage in replyList
set replyMessage to reply thisMessage with opening window
delay 2
set content of replyMessage to (("Hallo," & return & "hiermit bestätige ich den Einsatz." & return & "Mit besten Grüßen" & return & "Max Mustermann") as rich text)
end repeat
end tell

I now complete the full script based on your latest update.
I tested it with several cases, and it is 100% working for me. I just made couple of simplifications.
Also, I have set the targets (sender and content) on top of the script to make it easier to read and test (to test , I just have to change values of 4 lines on top with possible values from my mail box !).
set TargetSend to "#pos-lifestyle.de"
set Target1 to "nochmal alle wichtigen Informationen zum Heimspiel"
set Target2 to "deinen Einsatz per Mail"
set Target3 to "Bitte bestätige"
tell application "Mail"
set replyList to {}
set inboxMessages to every message in inbox whose sender contains TargetSend
repeat with thisMessage in inboxMessages
set thisContent to content of thisMessage
if (thisContent contains Target1) and (thisContent contains Target2) and (thisContent contains Target3) then
set end of replyList to thisMessage
set read status of thisMessage to true
end if
end repeat
# reply to all Einsatz mails
repeat with thisMessage in replyList
set replyMessage to reply thisMessage with opening window
delay 2
set content of replyMessage to (("Hallo," & return & "hiermit bestätige ich den Einsatz." & return & "Mit besten Grüßen" & return & "Max Mustermann") as rich text)
end repeat
end tell

I figured out a way to prevent this error from happening
set TargetSend to "#pos-lifestyle.de"
set Target1 to "nochmal alle wichtigen Informationen zum Heimspiel"
set Target2 to "deinen Einsatz per Mail"
set Target3 to "Bitte bestätige"
set MyName to "Max Musterman"
tell application "Mail"
set replyList to {}
set inboxMessages to every message in inbox whose sender contains TargetSend
# look for Einsatz mails
repeat with thisMessage in inboxMessages
set thisContent to content of thisMessage
if (thisContent contains Target1) and (thisContent contains Target2) and (thisContent contains Target3) then
set end of replyList to thisMessage
set read status of thisMessage to true
end if
end repeat
# reply to all Einsatz mails
repeat with thisMessage in replyList
set replyMessage to reply thisMessage with opening window
repeat until exists (window 1 whose name = "Re: " & subject of thisMessage)
end repeat
delay 0.1
tell application "System Events"
tell process "Mail"
set frontmost to true
keystroke "Hallo"
keystroke return
keystroke "Hiermit bestätige ich den Einsatz."
keystroke return
keystroke "Mit besten Grüßen"
keystroke return
keystroke MyName
keystroke return
end tell
end tell
#send replyMessage
end repeat
end tell

Related

VBScript Help clicking facebook menu item

Need help clicking a "friends" name in a drop down on Facebook via vbs. Full code below. I included pictures and referenced the images in the code to show what each part of the code does and the part I'm having trouble with. I've spent a full day and deep into the night on this one problem and from what I can tell, it SHOULD be working...but it's not... I disabled the "submit" feature of the script to prevent accidental submitting of the shared link while testing. Also, I used a series of wscript.sleep lines as opposed to ie.busy or readystate lines. I plan to fix this up later...
You'll need to replace "friendsName1" with an actual name from your friend list to test. You can add multiple separated by commas if you want it to iterate through multiple, but for testing, one is quickest:
DistNames = Array("friendsName1")
Any help would be awesome. Very stuck at the moment...
Image1|Image2|Image3|Image4|Image5
This is how it looks after you've clicked your friends name and it's been successfully added. I'm trying to achieve this with code...and failing.
Image6
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
set IE = createobject("internetexplorer.application")
IE.Visible = True
on error resume next
'===================================================================
'Navigates to login page
ie.navigate "https://www.facebook.com/"
wscript.sleep 2000
'===================================================================
'Logs into FB if you are not already
if not ie.document.all.item("email") is nothing then
ie.document.all.item("email").value = "username"
wscript.sleep 500
ie.document.all.item("pass").value = "password"
wscript.sleep 500
ie.document.all.item("loginbutton").click
wscript.sleep 2000
else
end if
DistNames = Array("friendsName1")
For each item in DistNames
ie.navigate "https://www.facebook.com/"
'===================================================================
wscript.sleep 4000
'===================================================================
'IMAGE1
'Clicks "share" to open menu
for each share in ie.document.getElementsbytagname("a")
if share.title = "Send this to friends or post it on your timeline." then
share.click
exit for
end if
next
'===================================================================
wscript.sleep 2000
'===================================================================
'IMAGE2
'Clicks "Share..."
for each share1 in ie.document.getElementsbytagname("a")
if instr(share1.getAttribute("ajaxify"),"story_container") > 0 then
share1.click
exit for
end if
next
'===================================================================
wscript.sleep 5000
'===================================================================
'IMAGE3
'Opens menu to select who you want it to go to
for each share2 in ie.document.getElementsbytagname("span")
if share2.innertext = "On your own Timeline" then
share2.click
exit for
end if
next
'===================================================================
wscript.sleep 1000
'===================================================================
'IMAGE4
'Selects "On a friend's Timeline"
for each share3 in ie.document.getElementsbytagname("span")
if share3.innertext = "On a friend's Timeline" then
share3.click
exit for
end if
next
'===================================================================
wscript.sleep 1000
'===================================================================
'IMAGE5 (Displays friend selection menu - this part works ok)
'Inserts name from array and opens list to click in the next step
for each share4 in ie.document.getElementsbytagname("input")
if share4.getAttribute("class") = "inputtext textInput" and share4.type = "text" then
share4.value = item
wscript.sleep 100
share4.blur
wscript.sleep 100
share4.click
exit for
end if
next
'===================================================================
wscript.sleep 2000
'===================================================================
'IMAGE5 cont... (Cannot click the name!)
'Clicks DistList name (not working!!!!)
for each share5 in ie.document.getElementsbytagname("span")
if share5.getAttribute("class") = "text" and share5.innertext = item then
share5.click
exit for
end if
next
'===================================================================
wscript.sleep 2000
'===================================================================
'Post body aka "Say something about this..."
for each share6 in ie.document.getElementsbytagname("textarea")
if share6.name = "message_text" then
share6.value = "Check out this post, " & item & "..."
exit for
end if
next
'===================================================================
wscript.sleep 3000
'===================================================================
'Clicks "Share Link"
'for each share6 in ie.document.getElementsbytagname("button")
'if share6.type = "submit" then
'share6.click
'exit for
'end if
'next
next
'===================================================================
wscript.sleep 3000
'===================================================================
wscript.sleep 500
wscript.echo "done"
wscript.quit

VBScript Outlook encounters encrypted email producing error 'Entrust Entelligence Security Provider'

I have an HTA and using VBScript to loop through Outlook email folders and get folder size. The HTA is run on a shared drive by staff, it is not an administrator tool. On occasion, my company will send encrypted emails. When the VBS hits one of these emails, the following happens:
1) VBS pauses.
2) Outlook displays the 'Entrust Entelligence Security Provider' error and asks the user to click 'OK'.
3) Once OK is clicked, the VBS continues.
The Outlook message does not bring focus to Outlook, so it is possible the user will not notice the message and continue to wait for the VBS to finish.
Is there any way of avoiding this message?
Here is my code:
public TotalSize
Sub OutlookDetail
TotalSize = 0
msgbox "Depending on the size of your Outlook account, this process may take up to 60 seconds" & vbcrlf & vbcrlf & _
"If you have encrypted emails, Outlook will make a sound and give you the 'Entrust Entelligence Security Provider' message. Click 'OK' to proceed."
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set colItems = objFolder.Items
For Each objItem in colItems
'THE OUTLOOK ERROR MAY OCCUR HERE
TotalSize = TotalSize + objItem.Size
Next
Set objInbox = objNamespace.GetDefaultFolder(olFolderInbox)
GetSubfolders(objInbox)
msgbox "The size of Inbox and all Subfolders: " & Round((TotalSize / 1048576),2) & " MB"
End Sub
Sub GetSubfolders(objParentFolder)
Set colFolders = objParentFolder.Folders
For Each objFolder in colFolders
Set objSubfolder = objParentFolder.Folders(objFolder.Name)
intSize = 0
Set colItems = objSubfolder.Items
For Each objItem in colItems
'THE OUTLOOK ERROR MAY ALSO OCCUR HERE
intSize = intSize + objItem.size
next
TotalSize = TotalSize + intSize
GetSubfolders objSubfolder
Next
End Sub

Using VBScript, how do I update Microsoft Outlook Inbox folder before accessing it in VBS?

The following is a VBScript (VBS) that I use the check for and process certain Outlook emails and attachments. The script finds the emails via their email address and subject. It then saves the attachment in a folder and moves the email to a folder within Outlook. (Most of this code was adapted from a stackoverflow.com post, but I have since forgotten which one.)
My issue: Sometimes this script has to be run before the user has opened Outlook for the day; therefore, none of the Outlook folders have been updated and the script can't find emails that have been sent to the user since the user shut Outlook down last.
My question: How do I update the Outlook inbox then proceed with the rest of the script ensuring that the Inbox is (or all Outlook folders are) completely updated? I'm not sure if VBS will wait for the folder update to happen, but if it won't, I, of course, need it to. I don't know how to update the inbox or wait for it to update if waiting is applicable.
Other tips on how to make the script better are welcome.
My VBScript:
Const olFolderInbox = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Call SaveAndMoveAttachment("'subject 1'", objFolder)
Call SaveAndMoveAttachment("'subject 2'", objFolder)
Call SaveAndMoveAttachment("'subject 3'", objFolder)
Set objFSO = Nothing
Set objOutlook = Nothing
Set objNamespace = Nothing
WScript.Quit
Sub SaveAndMoveAttachment(sSubject, objFolder)
Set colItems = objFolder.Items
Set colFilteredItems = colItems.Restrict("[Subject] = " & sSubject)
If colFilteredItems.count = 0 then
Msgbox "An email with subject " & sSubject & " in it was not found in your Outlook Inbox"
WScript.Quit
end if
For Each objMessage In colFilteredItems
Set colAttachments = objMessage.Attachments
intCount = colAttachments.Count
If intCount <> 0 and objMessage.Sender.Address = "support#somesite.com" Then
For i = 1 To intCount
strFileName = "Z:\somepath\" & objMessage.Attachments.Item(i).FileName
objMessage.Attachments.Item(i).SaveAsFile strFileName
'move the message to somefolder folder
Set objFoldersomefolder = objNamespace.GetDefaultFolder(olFolderInbox).Folders("somefolder")
objMessage.Move objFoldersomefolder
Next
End If
Next
Set colFilteredItems = Nothing
Set colAttachments = Nothing
Set colItems = Nothing
End Sub
Add logon step between above 2 lines
WSCript.Sleep 2000
objNamespace.Logon
objNamespace.SendAndReceive(True)
Below this line:
Set objNamespace = objOutlook.GetNamespace("MAPI")
Add this:
WSCript.Sleep 2000
objNamespace.SendAndReceive(True)
I found it here:
http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_28215854.html

why is this vbscript not fetching any value?

i am trying to write a vbscript that extracts the value from src attribute of an <img> tag that has a class attribute as this cs-poster-big
here is the code i have tried so far,
'Initializing object with Internet Explorer Application
set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
'setting properties of Internet Explorer to the newly create object
with IE
.Visible = 0
.navigate "http://www.roku.com/channels/#!details/12" 'INSERT WEBPAGE HERE
end with
'waiting for IE to load the page
'tried using IE.busy or IE.readyState <> 4 also
while IE.busy
wScript.sleep 500
wend
wScript.sleep 500
'getting all image tags from the webpage
Set imgTags = IE.document.getElementsByTagName("IMG")
'iterating through the image tags to find the one with the class name specified
For Each imgTag In imgTags
'tried imgTag.className also
If imgTag.getAttribute("class") = "cs-poster-big" Then MsgBox "src is " & imgTag.src
next
IE.quit
set IE= Nothing
MsgBox "End of script"
and it is not displaying any value but you can view the source of the page here and you can see it has an <img> tag with class cs-poster-big
i don't understand why it is not displaying in my script
Do While IE.Busy Or IE.ReadyState <> 4
WScript.Sleep 500
Loop
Wait until page is completely loaded.
EDIT - While this works in IE10, IE8 fails to locate the image. Not tested in other versions.
In this case, try to change your url to
http://www.roku.com/channels?_escaped_fragment_=details/12/netflix#!details/12/netflix
to avoid problems with the dynamic generate content.
Also, in IE8, code needs to be changed to get class name of the image. It should be
Do While IE.Busy Or IE.ReadyState <> 4
WScript.Sleep 100
Loop
Set imgTags = IE.document.getElementsByTagName("IMG")
For Each imgTag In imgTags
imgClass = imgtag.getAttribute("class")
If IsNull( imgClass ) Then
imgClass = imgTag.className
End If
If imgclass = "cs-poster-big" Then
MsgBox "src is " & imgTag.src
End If
Next
But not a solution, just a workaround.

Mail Rule to Run Applescript Not Working?

Question for my fellow AppleScripters. I have the following script which runs just fine if you run it in AppleScript Editor or Script Debugger, but that won't run at all if you try to run it from a Mail rule. The script is correctly placed in ~/Library/Application Scripts/com.apple.mail, and shows up in the "Run AppleScript" menu in the Mail rule, but simply refuses to work when new mail arrives.
on perform_mail_action(info)
tell application "Mail"
set theMessages to |SelectedMessages| of info
repeat with thisMessage in theMessages
set AppleScript's text item delimiters to {""}
set thisSender to sender of thisMessage as string
set quotepos to offset of "\"" in thisSender
if (quotepos is not 0) then
set thisSender to (text items (quotepos + 1) through -1) ¬
of thisSender as string
set quotepos to offset of "\"" in thisSender
if (quotepos is not 0) then
set thisSender to (text items 1 through (quotepos - 1)) ¬
of thisSender as string
end if
else
set atpos to offset of "#" in thisSender
if (atpos is not 0) then
set thisSender to (text items 1 through (atpos - 1)) ¬
of thisSender as string
end if
set brkpos to offset of "<" in thisSender
if (brkpos is not 0) then
set thisSender to (text items (brkpos + 1) through -1) ¬
of thisSender as string
end if
end if
tell application "Finder" to say "Mail from " & thisSender
end repeat
end tell
end perform_mail_action
Any ideas?
Thanks for the feedback everyone, but I figured out the problem. It wasn't anything to do with the script at all . . . it was that I had Satimage.osax installed in my scripting additions folder, and since it's not fully ML compatible yet, it messed everything up. Once I uninstalled it, all my folder actions started working great!
Thanks!
--Andy H.