Example: Sending An Email Through Outlook

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Brett
    Indigo Rose Staff Member
    • Jan 2000
    • 2001

    Example: Sending An Email Through Outlook

    Using the LuaCOM plugin, you can easily initiate an email message complete with attachments though MS Outlook's COM API.

    Here is some sample code that will make an email message through Outlook. Note that I have only tested this on Outlook 2000 using v1.0.0.2 of the LuaCOM plugin.

    Code:
    olMailItem = 0;
    Outlook = luacom.CreateObject("Outlook.Application");
    EmailMessage = Outlook:CreateItem(olMailItem);
    
    EmailMessage.To = "[email protected]";
    EmailMessage.CC = "[email protected]";
    EmailMessage.Subject = "This is a test!";
    EmailMessage.Body = "I love to send email!\r\nHow about you?";
    EmailMessage.Attachments:Add("C:\\File 1.txt");
    -- Add other attachments...
    -- EmailMessage.Attachments:Add("C:\\File 2.txt");
    
    EmailMessage:Display();
    
    EmailMessage = nil;
    Outlook = nil;
    You can do a whole lot more than this as well such as setting up appointments and enumerating mail and contact items. Consult the MS Outlook COM model documentation for more details.
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    #2
    Big Thanks

    Brett,

    After seeing your example, I was able to figure out how to do the Outlook Appointment thing using LUAcom. Here are the results.

    Code:
    function ScheduleMeeting()
    	myolApp = luacom.CreateObject("Outlook.Application");
    	myNameSpace = myolApp:GetNamespace("MAPI");
     	olAppointmentItem = 1;
     	myItem = myolApp:CreateItem(olAppointmentItem);
     	
     	myItem.RequiredAttendees = "[email protected]";
     	olMeeting = 1
    	myItem.MeetingStatus = olMeeting;
    	myItem.Subject = "Strategy Meeting";
    	myItem.Body = "Lets get together to discuss the possibility of becoming a client.";
    	myItem.Location = "Conference Room B";
    	myItem.Start = "1:30 PM 2/28/05";
    	myItem.End = "3:00 PM 2/28/05";
    	myItem:Display();
    	--uncomment to automatically send rather then display and comment the display item above.
    	--myItem:Send();
    	
    	myolApp = nil;
    	myNameSpace = nil;
    	myItem = nil;
    end
    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

    Comment

    • Intrigued
      Indigo Rose Customer
      • Dec 2003
      • 6138

      #3
      You guys are making the LuaCOM plugin look pretty easy to use, once you get the syntax down!

      :yes
      Intrigued

      Comment

      • TJ_Tigger
        Indigo Rose Customer
        • Sep 2002
        • 3159

        #4
        Here is another forum where someone took the time to write down a lot about the luacom and COM objects information and give examples. I found the site using google and this is where I found the TTS examples that are posted elsewhere on the IR forums.

        TJ-Tigger
        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
        "Draco dormiens nunquam titillandus."
        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

        Comment

        • Brett
          Indigo Rose Staff Member
          • Jan 2000
          • 2001

          #5
          VERY cool link. Here is code to get the size of a folder withour parsing through it file by file:

          Code:
          function GetFolderSize(FolderName)
          	fso = luacom.CreateObject("Scripting.FileSystemObject");
          	folderOb = fso:GetFolder(FolderName);
          	local Size = folderOb.size;
          	
          	fso = nil;
          	folderOb = nil;
          	
          	return Size;
          end
          
          local strFolder = "C:\\Temp";
          local Size = GetFolderSize(strFolder);
          Dialog.Message("Size of: "..strFolder,Size.." bytes");

          Comment

          • Intrigued
            Indigo Rose Customer
            • Dec 2003
            • 6138

            #6
            Both cool! TJ_TIGGER, I like the amount of quality links on the page (link) you posted!

            I just learned that a period '.' is how you get at the properties and a colon ':' is how you get at the methods and you do need to clean up afterwards (garbage collection).

            Very cool indeed!

            I like the folder code chunk (Code Keeper bound it be)!

            *rolls on the floor like an excited kid on Christmas day*
            Intrigued

            Comment

            • Intrigued
              Indigo Rose Customer
              • Dec 2003
              • 6138

              #7
              Folder Size - luaCOM - Function - Intrigued

              I added to the code Brett put forth.

              Now, the Dialog.Message dialog will show a couple of lines of data with a tad more human readability (Linux crowd think -h):


              Code:
              [SIZE=1]function GetFolderSize(FolderName)
              	fso = luacom.CreateObject("Scripting.FileSystemObject");
              	folderOb = fso:GetFolder(FolderName);
              	local Size = folderOb.size;
              	
              	fso = nil;
              	folderOb = nil;
              	
              	return Size;
              end
              
              local Size = GetFolderSize(_TempFolder);
              
              if Size >= 1073741824 then
              	Size = Size/1024; Size = Size/1024; Size = Size/1024;
              		Size = Math.Round(Size, 1);
              			Size = Size.." GB";
              		
              elseif Size >= 1048576 then
              	Size = Size/1024; Size = Size/1024;
              		Size = Math.Round(Size, 1);
              			Size = Size.." MB";
              		
              elseif Size >= 1024 then
              	Size = Size/1024
              		Size = Math.Round(Size, 1);
              			Size = Size.." KB";
              		
              else
              	Size = Math.Round(Size, 1);
              end
              
              
              Dialog.Message("Notice","Location: ".._TempFolder.."\nSize: "..Size);[/SIZE]
              See any code hiccups? Please clue me in. I tried this only on one folder so far.
              Intrigued

              Comment

              • Intrigued
                Indigo Rose Customer
                • Dec 2003
                • 6138

                #8
                Here's a sample project:

                SEE: Attachment
                Attached Files
                Intrigued

                Comment

                • Intrigued
                  Indigo Rose Customer
                  • Dec 2003
                  • 6138

                  #9
                  Updated (added a suffix for the Bytes listing):
                  Code:
                  function GetFolderSize(FolderName)
                  	fso = luacom.CreateObject("Scripting.FileSystemObject");
                  	folderOb = fso:GetFolder(FolderName);
                  	local Size = folderOb.size;
                  	
                  	fso = nil;
                  	folderOb = nil;
                  	
                  	return Size;
                  end
                  
                  local Size = GetFolderSize(_TempFolder);
                  
                  if Size >= 1073741824 then
                  	Size = Size/1024; Size = Size/1024; Size = Size/1024;
                  		Size = Math.Round(Size, 1);
                  			Size = Size.." GB";
                  		
                  elseif Size >= 1048576 then
                  	Size = Size/1024; Size = Size/1024;
                  		Size = Math.Round(Size, 1);
                  			Size = Size.." MB";
                  		
                  elseif Size >= 1024 then
                  	Size = Size/1024
                  		Size = Math.Round(Size, 1);
                  			Size = Size.." KB";
                  		
                  else
                  	Size = Math.Round(Size, 1);
                                   [B]Size = Size.." Bytes";[/B] [COLOR=DarkGreen]-- Added this line in[/COLOR]
                  end
                  
                  
                  Dialog.Message("Notice","Location: ".._TempFolder.."\nSize: "..Size);
                  Intrigued

                  Comment

                  • SUF6NEWBIE

                    #10
                    Very Cool stuff Gentlemen..tks for LUACom Brett

                    Comment

                    • Brett
                      Indigo Rose Staff Member
                      • Jan 2000
                      • 2001

                      #11
                      Originally posted by SUF6NEWBIE
                      Very Cool stuff Gentlemen..tks for LUACom Brett
                      It is cool indeed. Don't thank me too much - I just re-wrapped someone else's hard work. I just thought it was a gret extension library and wanted to see it available to our customers as well. I am probably going to start a consolidated list of LuaCOM example scripts on the icynorth.com forums so if anyone posts examples here feel free to post them there as well (in the Plugins and DLLs forum).

                      Comment

                      • TJ_Tigger
                        Indigo Rose Customer
                        • Sep 2002
                        • 3159

                        #12
                        Originally posted by Brett
                        It is cool indeed. Don't thank me too much - I just re-wrapped someone else's hard work. I just thought it was a gret extension library and wanted to see it available to our customers as well. I am probably going to start a consolidated list of LuaCOM example scripts on the icynorth.com forums so if anyone posts examples here feel free to post them there as well (in the Plugins and DLLs forum).

                        [Crush]You Rock Dude[/Crush]
                        TJ-Tigger
                        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                        "Draco dormiens nunquam titillandus."
                        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                        Comment

                        • Derek
                          Indigo Rose Customer
                          • May 2001
                          • 1254

                          #13
                          Originally posted by TJ_Tigger
                          [Crush]You Rock Dude[/Crush]
                          I agree! Never thought i'd have an idol, but I just nominated Brett to be my idol til my life's end
                          -
                          = Derek
                          ["All glory comes from daring to begin" - fortune cookie]

                          Comment

                          • Dermot
                            Indigo Rose Customer
                            • Apr 2004
                            • 1791

                            #14
                            ADO Example

                            Here is an example using luacom and ADO to read records from an Access database.

                            I got the code from here:


                            Dermot
                            Last edited by Dermot; 05-09-2007, 11:26 PM.
                            Dermot

                            I am so out of here :yes

                            Comment

                            • Derek
                              Indigo Rose Customer
                              • May 2001
                              • 1254

                              #15
                              Great link Dermot.

                              Thought: I have no doubt that AMS5 is the most universally awesome program on the planet :yes
                              -
                              = Derek
                              ["All glory comes from daring to begin" - fortune cookie]

                              Comment

                              Working...
                              X