Applies To:
  • CitectSCADA 5.xx
  • CitectHMI 5.xx

With security enhancements made to Outlook, due to concerns caused by the running of scripts and the spreading of viruses, the maillogon() mailsend() Cicode functions in Citect seem to not work as they should. It will not start up Outlook, nor will it send the mail as specified in my Cicode. Is there a way to over come this problem? 

There are a few steps you can take to make this work. Before we do this, have a read of KB Article Q2262 to give you an understanding of how the maillogon(), mailsend() and maillogoff() functions are to be used.

1) The first step is to make sure that Outlook is running on the system and the user is logged into Outlook using their username and password. Once you know that you are logged on correctly and Outlook is running then the function should work fine.

However in some cases on Outlook 98/2000, depending on the security settings done by the network administrator you may get the following prompt:

To overcome this, start NOTEPAD in Windows (Start | Programs | Accessories | Notepad), and from here cut and paste the following code into Notepad

Windows Registry Editor Version 5.00

Now save this file somewhere local to you (such as your Windows Desktop) but when saving it make sure you select 'Save As' type'All File Types' and name it with the extension 'reg' (ideally something like "security.reg"). Once it is saved on your desktop, make sure that you are logged on at least as a Power User if not an Administrator on the System and double click on the file that you have created.

This should bring up the following prompt

Once you click 'Yes' on the prompt then it will inform you that the code was successfully added into your registry window where you will click on 'OK' to confirm the changes.

2) The other note to be aware of, and should be dealt with by a network administrator, is that Microsoft has a Knowledge Base article for Administrators of Outlook. This is known as OL2000: Administrator Information About the Outlook E-mail Security Update. The information in the article applies to: Microsoft Outlook 2000

This article was previously published under Q263297

The article can be found at the following URL

This issue should be addressed promptly to make sure that this Citect function will work.  This is not a Citect problem but a security measure taken by Microsoft to prevent malicious activities through the use of email.

3) If Outlook is not already up and running then the following example code can be used to start up Outlook. Here we allow 5 seconds for Outlook to load using the Cicode Sleep(); function, as it may take time to load applications based on the speed of your machine. Again you can look at KB Article Q2262 for further explanation on the cicode.

// Function Name to be used - in this example TestMail
Function TestMail

//This starts up Outlook using the EXEC( ); Cicode function.  Your install path may differ from the example. Please check your Outlook installation path prior to setting this section.
Exec("C:\Program Files\Microsoft Office\Office\Outlook.exe");

//Wait 5 seconds for Outlook to load before continuing your Cicode

//Logs the user onto Microsoft Outlook with a specified password

//Sends a message with an attachment
MailSend("sName","Mail Subject","Body of the email message","[data]:message.txt",0);

MailLogoff(); //logoff the user 

END; //End your function

This can now be called within your Citect project either through a button on a page or even using an event to trigger it. However there is still going to be the issue of whether or not you want MS Outlook to stay running once your function is complete. Since Citect has an EXEC command but does not have a command to close off an external / 3rd party application it will be necessary to either close the email program manually or write a Visual Basic Script file that again can be run using the cicode EXEC( ); function

The simplest way to create this is using Windows Notepad and saving the file type as a VBS.  The VBS code in its simplest form can be cut and pasted into Notepad and saved as outlined below:

In this example the file is saved as exitfunct.vbs


Sub exitfunct()

dim xOutlook
     set xOutlook = createobject("outlook.application")
End Sub



The reason the code was done in VBS and not VBA is that some other users out there still use versions of Citect that have not yet had the VBA components added to them, but the process to perform this function would still be similar in VBA.

Once your VBS is written then the CiCode file that you create would look something like the following:

(NOTE: Check your local paths and filenames to makes sure they correspond to that of your systems file structure)

//Create the function
FUNCTION testmail;

Exec("C:\Program Files\Microsoft Office\Office\Outlook.exe");

        Sleep(5); //Wait 5 seconds for outlook to load before continuing your cicode

            //Logon to outlook

                                       //send email from user, subject, message body, an attachment
            MailSend("sName","Subject goes here","Message Body","[DATA]filename.txt",0);

                                     //logoff the user

        Sleep(10); //Wait 10 seconds for the email and attachment
        to send before closing outlook

    // Run the VBScript to close off Outlook
    Exec("C:\WinNT\System32\cscript.exe c:\temp\exitfunct.vbs");

END //End of our function

The file and directory structures in the above cicode are based on the system it was tested on, once again please make sure that you have the correct path names for your code to work.