win32ole, outlook, ruby 1.8

Discussion in 'Ruby' started by Greg Brondo, Dec 22, 2003.

  1. Greg Brondo

    Greg Brondo Guest

    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
     
    Greg Brondo, Dec 22, 2003
    #1
    1. Advertising

  2. Greg Brondo

    Greg Brondo Guest

    Here's the error I receive when attempting a listed method:

    WIN32OLERuntimeError: Move
    OLE error code:0 in <Unknown>
    <No Description>
    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" <> wrote in message
    news:daFFb.1481$...
    > 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
    >
    >
     
    Greg Brondo, Dec 22, 2003
    #2
    1. Advertising

  3. Greg Brondo

    Eric Hodel Guest

    --aPdhxNJGSeOG9wFI
    Content-Type: text/plain; charset=us-ascii
    Content-Disposition: inline
    Content-Transfer-Encoding: quoted-printable

    Greg Brondo () wrote:

    > Here's the error I receive when attempting a listed method:
    >=20
    > WIN32OLERuntimeError: Move
    > OLE error code:0 in <Unknown>
    > <No Description>
    > 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
    >=20
    >=20
    > However, methods like 'Copy' work just fine.


    How about a snippet of the code you're using?

    --=20
    Eric Hodel - - http://segment7.net
    All messages signed with fingerprint:
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


    --aPdhxNJGSeOG9wFI
    Content-Type: application/pgp-signature
    Content-Disposition: inline

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (FreeBSD)

    iD8DBQE/5zMRMypVHHlsnwQRAuz7AKDE9yyTMadqlJ3EAn9cOZJFaYARMQCeKHqi
    xJbJ4wXBFncPTirJwc/fJe0=
    =wKyY
    -----END PGP SIGNATURE-----

    --aPdhxNJGSeOG9wFI--
     
    Eric Hodel, Dec 22, 2003
    #3
  4. Greg Brondo

    Greg Brondo Guest

    ACK! Never mind. Figured it out. The move method takes an outlook folder
    object as a parameter...Yahoo!!!

    Greg B.

    "Greg Brondo" <> wrote in message
    news:44GFb.1494$...
    > Here's the error I receive when attempting a listed method:
    >
    > WIN32OLERuntimeError: Move
    > OLE error code:0 in <Unknown>
    > <No Description>
    > 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" <> wrote in message
    > news:daFFb.1481$...
    > > 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
    > >
    > >

    >
    >
     
    Greg Brondo, Dec 22, 2003
    #4
  5. Greg Brondo

    James Toomey Guest

    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?
     
    James Toomey, Dec 23, 2003
    #5
  6. Greg Brondo

    Greg Brondo Guest

    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" <> wrote in message
    news:...
    > 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?
     
    Greg Brondo, Dec 23, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Tuckner

    [WIN32OLE] Outlook Automation Question

    Steve Tuckner, Jun 26, 2003, in forum: Ruby
    Replies:
    0
    Views:
    185
    Steve Tuckner
    Jun 26, 2003
  2. Masaki Suketa
    Replies:
    4
    Views:
    384
    Dave Burt
    Mar 27, 2006
  3. baon
    Replies:
    4
    Views:
    171
  4. Alex DeCaria
    Replies:
    10
    Views:
    419
    Alex DeCaria
    Dec 13, 2007
  5. zxem
    Replies:
    1
    Views:
    237
Loading...

Share This Page