Industrial Automation
Industrial Automation | Europe


Main > Product Type > Software > Visualisation
Minimize Text   Default    Enlarge Text


Sample For Sending Email From CX-Supervisor

This is a sample application showing how to send an email from CX-Supervisor. It uses VBScript objects as based on the article How To Send An Email Alert From A PC Using VB Script.
Microsoft VBScript supports CDO.Message object for handling email messages. By creating the object and setting the required properties we can use it to send an email.  For most users who don't have an SMTP mail server running on there machine, you will have to configure the connection to a remote SMTP mail server.  This can be your corporate server or can even use the standard Google gmail servers.

The attached example allows you to enter the email address, subject and body text and then send the email. It requires CX-Supervisor version 3.3 or later to open but the script should work in any version.

You will need to modify the example to add:

  • Your email account name (for the sendusername field)
  • Your email password (for the sendpassword field). This is so the CDO.Message object can log in to your email account to send the mail.
  • If you are not using gmail, your SMTP server (for smtpserver field)

Fig. View of example

The following code is used to send the email message.
on error resume next

Const schema = ""
Dim objMsg, oConf

' E-mail properties
Set objMsg = CreateObject("CDO.Message")
objMsg.To = txtRecipient ' or "Recipient Name <>"
objMsg.Subject = txtSubject
objMsg.From = txtSenderName ' or "Sender Name <>"
'Add cc & bcc like this
'objMsg.Cc = ""
'objMsg.Bcc = ""

' Add attachments like this, specifying the file name with full path
'objMsg.AddAttachment (FileName1)

objMsg.TextBody = txtBodyText

' GMail SMTP server configuration and authentication info
Set oConf = objMsg.Configuration
oConf.Fields(schema & "smtpserver") = "" 'server address
oConf.Fields(schema & "smtpserverport") = 25 'email port number (sometimes 465 or 587)
oConf.Fields(schema & "sendusing") = 2 ' Send Using Port (cboSendUsingPort)
oConf.Fields(schema & "smtpauthenticate") = 1 'authentication type (cboBasic)
oConf.Fields(schema & "smtpusessl") = True 'use SSL encryption
oConf.Fields(schema & "sendusername") = "" 'sender account username
oConf.Fields(schema & "sendpassword") = "password" 'sender account password

' send message

' Report any error
If Err.Number <> 0 AND Err.Number <> 1041 then
    MsgBox "ERROR " & Err.Number & ": " & Err.Description
    Err.Number= 0
    MsgBox "Message sent OK"
end if

If you are using gmail SMTP server then you may get error "The message could not be sent to the SMTP server. The transport error code was 0x80040217.". For secure accounts you can create a unique application password to use for this service. For more info about configuring your gmail account to use "App Passwords" see Google Account: Sign in with App passwords and create a 'custom' password for this script. 
For more help on the CDO.Message object see Microsoft MSDN

Attachments - Size: 9892

Comments (View All Comments / Add Comment)

Related Articles
No related articles found.
Created 2017-06-01
Modified 2017-06-01
Views 5613


You are not logged in.