Industrial Automation
Industrial Automation | Europe

myKnowledge

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

Print
E-mail

Sample For Sending Email From CX-Supervisor


Introduction
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.
Details
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.
Example
 

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 = "http://schemas.microsoft.com/cdo/configuration/"
Dim objMsg, oConf

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

' 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") = "smtp.gmail.com" '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") = "youraccount@gmail.com" 'sender account username
oConf.Fields(schema & "sendpassword") = "password" 'sender account password
oConf.Fields.Update()

' send message
objMsg.Send()

' Report any error
If Err.Number <> 0 AND Err.Number <> 1041 then
    MsgBox "ERROR " & Err.Number & ": " & Err.Description
    Err.Number= 0
Else
    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

eMail_demo.zip - Size: 9892


Comments (View All Comments / Add Comment)

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

 

You are not logged in.