Forum Discussion
Thank you so much Marsha for the response.
I mean it just worked onetime randomly in the middle. I am not sure about the reason. Well, i would try as you said. Could you tell me what i need to add in the below code which is in javascript.
// MS Outlook constants
var
olMailItem = 0;
olByValue = 1;
olContactItem = 2;
var MsOutlook, NS, ContactFldr;
function Outlook_Test()
{
if (!InitializeOutlook())
Log.Warning("Unable to initialize MS Outlook or its folders.", "", pmHigher);
else
{
SendReport("source email", "destination email", "company",
"D:\\Data\\TestDocument.txt");
}
}
// Initializes MS Outlook
function InitializeOutlook()
{
try
{
try
{
MsOutlook = Sys.OleObject("Outlook.Application");
}
catch(exception)
{
MsOutlook = Sys.OleObject("Outlook.Application.16");
}
// NS = MsOutlook.GetNamespace("MAPI");
// ContactFldr=NS.AddressLists;
//ContactFldr = NS.Folders("Personal Folders").Folders("Contacts");
}
catch(exception)
{
Log.Warning(exception+"Unable to initialize MS Outlook.", "", pmHigher);
return false;
}
return true;
}
// Sends a report to the user
function SendReport(Name1, Name2, Company, FileNameToAttach)
{
var ObjItem, MI, i, CRLF;
CRLF = "\n";
// Creates a new message
MI = MsOutlook.CreateItem(olMailItem);
// Sets the message subject
MI.Subject = "Test Results";
MI.Body= "Sample test";
// Specifies the destination address
MI.To = "Destination address";
// Attaches the script code
MI.Attachments.Add(FileNameToAttach, olByValue, MI.Body.length, "Script");
MI.Display(); // This line displays the new mail on screen.
// To send the mail, use the Send method
MI.Send();
}
To me code seems to be OK
Just make sure in your registary (regedit .exe) \HKEY_CLASSES_ROOT\Outlook.Application\CurVer is 1.6
since it says server execution failed it seems that your out look can not get connected to mail server
One thing you have to aware that if outlook already open it can not open another instance.
try before initializing outlook something like...
if (Sys.Process("OUTLOOK").Exists){
Sys.Process("OUTLOOK").Terminate}
Also try opening TC as administrator there could be privileged issue
Other thing may be your antivirus or system admin rule restricts you.
Related Content
Recent Discussions
- 9 hours agoSubhraDas