Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Pipe email to application on Windows

  • 09-10-2008 04:00PM
    #1
    Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭


    I want to get an email piped to an application on a windows 2003 server (Plesk installed). Is this possible? I was told my my VPS admins that it isn't, but come on! it's gotta be.

    Anyone have any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    No one know how to do this?

    What about an Outlook script to pass on the email? Is it possible to do a POST from an Outlook script?


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    You can always use VBS to send email using MAPI

    Or do you want to send an email to your application?

    Otherwise, you can always have a quick and dirty service that just saves the email to a location that you can parse it.


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    I want to sent it to an application. Saving to disk will work. Do you happen to know how to do this in a macro? I have managed to save the attachments to disk, but can't work out how to save the contents.


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Item.SaveAs "c:\test.msg", olMSG within Outlook or where you can reference the Outlook DLL (early binding)

    Otherwise if you are using late binding (creating the object from the type name) use the value 3 for olMsg or define olMSG as 3

    Sample

    http://cwashington.netreach.net/depo/view.asp?Index=948

    Gives you an idea on how to save the file to the hard disk


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Thanks Ginger.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Do this as a .NET service with the interop classes and you can log into a mail box and save the files to your hard disk and then get your progam to pick it up ..

    Or else if you have control over the programs code, create a mailbox for it and get it to log into its own mailbox and get the data that way.


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Cool, got it.
    Thanks.
    using System;
    using Microsoft.Office.Interop.Outlook;
    
    namespace Office
    {
        class Program
        {
            static void Main(string[] args)
            {
                Microsoft.Office.Interop.Outlook.Application app = null;
                Microsoft.Office.Interop.Outlook._NameSpace ns = null;
                Microsoft.Office.Interop.Outlook.MailItem item = null;
                Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
                Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
    
                try 
                {
                      app = new Microsoft.Office.Interop.Outlook.Application();
                      ns = app.GetNamespace("MAPI");
                      ns.Logon(null,null,false, false);
    
                      inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                      subFolder = inboxFolder.Folders["Test"]; //folder.Folders[1]; also works
                      Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
                      Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());
    
                          for(int i=1;i<=subFolder.Items.Count;i++)
                          {                 
                              item = (Microsoft.Office.Interop.Outlook.MailItem)subFolder.Items[i];
                              Console.WriteLine("Item: {0}", i.ToString());
                            Console.WriteLine("Subject: {0}", item.Subject);
                            Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());
                            Console.WriteLine("Categories: {0}", item.Categories);
                            Console.WriteLine("Body: {0}", item.Body);
                            Console.WriteLine("HTMLBody: {0}", item.HTMLBody);
                          }
                        }
                        catch (System.Runtime.InteropServices.COMException ex)
                        {
                          Console.WriteLine(ex.ToString());
                        }
                        finally
                        {
                          ns = null;
                          app = null;
                          inboxFolder = null;
                        }
            }
        }
    }
    

    modified from http://geekswithblogs.net/timh/archive/2006/05/26/79720.aspx


Advertisement