I’m using ruby 1.8 on Windows via rubyinstaller accessing outlook with
win32ole. When I create an outlook.application object and then create a
message instance I’m not able to ‘Move’ or ‘Delete’ the message even though
the methods are listed in ole_methods. However, many other methods work
like a champ.
Any ideas?
Greg Brondo
Here’s the error I receive when attempting a listed method:
WIN32OLERuntimeError: Move
OLE error code:0 in
HRESULT error code:0x8002000f
Parameter not optional
from (irb):16:in `method_missing’
from (irb):16
However, methods like ‘Copy’ work just fine.
Thanks,
Greg B.
“Greg Brondo” greg@brondo.com wrote in message
news:daFFb.1481$pt3.384@chiapp18.algx.net…
I’m using ruby 1.8 on Windows via rubyinstaller accessing outlook with
win32ole. When I create an outlook.application object and then create a
message instance I’m not able to ‘Move’ or ‘Delete’ the message even
though
···
from :0
the methods are listed in ole_methods. However, many other methods work
like a champ.
Any ideas?
Greg Brondo
Here’s the error I receive when attempting a listed method:
WIN32OLERuntimeError: Move
OLE error code:0 in
HRESULT error code:0x8002000f
Parameter not optional
Are you specifying the destination folder as the argument?
from (irb):16:in `method_missing'
from (irb):16
from :0
However, methods like ‘Copy’ work just fine.
How about a snippet of the code you’re using?
···
Greg Brondo (greg@brondo.com) wrote:
–
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
ACK! Never mind. Figured it out. The move method takes an outlook folder
object as a parameter…Yahoo!!!
Greg B.
“Greg Brondo” greg@brondo.com wrote in message
news:44GFb.1494$pt3.311@chiapp18.algx.net…
···
Here’s the error I receive when attempting a listed method:
WIN32OLERuntimeError: Move
OLE error code:0 in
HRESULT error code:0x8002000f
Parameter not optional
from (irb):16:in `method_missing’
from (irb):16
from :0
However, methods like ‘Copy’ work just fine.
Thanks,
Greg B.
“Greg Brondo” greg@brondo.com wrote in message
news:daFFb.1481$pt3.384@chiapp18.algx.net…
I’m using ruby 1.8 on Windows via rubyinstaller accessing outlook with
win32ole. When I create an outlook.application object and then create a
message instance I’m not able to ‘Move’ or ‘Delete’ the message even
though
the methods are listed in ole_methods. However, many other methods work
like a champ.
Any ideas?
Greg Brondo
This code successfully deleted the email with the subject line “Delete
Me” when I tried it:
require 'win32ole’
olApp = WIN32OLE.new(‘Outlook.Application’)
#The number 6 is the constant olFolderInbox.
inbox = olApp.GetNamespace(‘MAPI’).GetDefaultFolder(6)
emailItems = inbox.Items
emailItems.each {|x|
if x.Subject == ‘Delete Me’ then
x.Delete
end
}
What does your original code look like?
I figured it out. It needed an outlook folder object for the move to work.
Here’s the code:
require ‘win32ole’
require ‘yaml’
reList = YAML::load(File.open(‘rSpamAndSpam.re’))
def checkSpam(msgBody, reList)
isSpam = false
reList.each do |re|
if msgBody =~ re
isSpam = true
break
end
end
return isSpam
end
outlookInbox = 6
outlookDeletedItems = 3
objOutlook = WIN32OLE.new(‘Outlook.Application’)
objNameSpace = objOutlook.GetNamespace(“MAPI”)
objFolder = objNameSpace.GetDefaultFolder(outlookInbox)
delFolder = objNameSpace.GetDefaultFolder(outlookDeletedItems)
objFolder.Items.each do |i|
puts “-” * 60
puts i.Subject
isSpam = checkSpam(i.Body, reList)
puts “Spam = #{isSpam}”
if isSpam
puts i.Body
i.Move(delFolder)
exit
end
end
Thanks!
“James Toomey” jamesvtoomey@yahoo.com wrote in message
news:8fd3ee12.0312221722.4e5c77ba@posting.google.com…
···
This code successfully deleted the email with the subject line “Delete
Me” when I tried it:
require ‘win32ole’
olApp = WIN32OLE.new(‘Outlook.Application’)
#The number 6 is the constant olFolderInbox.
inbox = olApp.GetNamespace(‘MAPI’).GetDefaultFolder(6)
emailItems = inbox.Items
emailItems.each {|x|
if x.Subject == ‘Delete Me’ then
x.Delete
end
}
What does your original code look like?