Script example

The following example uses objects from the Microsoft Outlook Object Library to create a mail message, resolve the recipient’s e-mail address, and send the mail message if the recipient’s e-mail address has been resolved.

local Outlook.Application app;
local Outlook.NameSpace nameSpace;
local Outlook.MAPIFolder folder;
local Outlook.MailItem mailItem;
local Outlook.Recipient recipient;

local boolean resolved;
local integer i;

{If Outlook is running, use it. Otherwise, create a new instance.}
app = COM_GetObject("Outlook.Application");
if(app = null) then
	app = new Outlook.Application();
end if;

{Get a namespace.}
nameSpace = app.GetNameSpace("MAPI");

{Retrieve the default Inbox folder and display it.}
folder = nameSpace.GetDefaultFolder(Outlook.olFolderInbox);
folder.Display();

{Create a new mail message.}
mailItem = app.CreateItem(Outlook.olMailItem);

{Add a recipient to the mail message.}
recipient = mailItem.Recipients.Add("Kim Akers");

{Resolve the addresses of the mail message’s recipients.}
resolved = recipient.Resolve();

{Specify the mail message’s subject and body.}
mailItem.Subject = "Houses that matched your profile.";
mailItem.Body = "The attachment details the houses that matched" + "your profile.  -Steve";

{Add an attachment to the mail message.}
mailItem.Attachments.Add("C:\RESM\Houses.txt", none, none,  "Matched Houses");

{Display the mail message.}
mailItem.Display();

{If the recipient’s address has been resolved, send the mail message. Otherwise, warn the user that the message cannot be sent.}
if(resolved) then
	mailItem.Send();
else
	warning "Cannot send message. E-mail address has not been"  + "resolved.";
end if;

{Close Outlook.}
app.Quit();

{Clear variables.}
clear mailItem;
clear folder;
clear nameSpace;
clear app;

 


Documentation Feedback