Forum Discussion
Are you closing Outlook at the end of your test? If you're opening it every time and not closing it, that would explain why it can't open after the first time.
- ManuT7 years agoOccasional Contributor
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();
}- NisHera7 years agoValued Contributor
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.
- Marsha_R7 years agoChampion Level 3
tristaanogre got javascript? :robothappy:
Related Content
Recent Discussions
- 5 hours agoJacobjacob44