From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Send an Email from DIAdem

Code and Documents

Attachment

Overview

This script will allow you to have email capabilities within DIAdem

Description

I had been trying to use the script at the following location to email from DIAdem-

https://forums.ni.com/t5/Example-Program-Drafts/Send-an-Email-From-DIAdem/ta-p/3525692

 

However I have been having some problems with it, I believe specifically the CDO ActiveX parts. This script is a bit simpler, and is working well so far, and therefore I thought it might be useful for other people to see it. This script is an edited version of an example I was sent.

 

 

'-- VBS script for Sending Email from DIAdem
'-- Created on 04/03/2017 15:34:04
'-- Author: Sarah Corsham, NI UK
'-- Comment: 
'-------------------------------------------------------------------------------
Option Explicit  'Forces the explicit declaration of all the variables in a script.
Call SendEmail
'-------------------------------------------------------------------------------------
'-------------------------------------Send Email--------------------------------------
'-------------------------------------------------------------------------------------
Public Function SendEmail()
Dim objOutl, olMailItem, objMailItem, strEmailAddr
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
'comment the next line if you do not want to see the outlook window
objMailItem.Display
strEmailAddr  =                                                                 'Insert email address to be sent from
objMailItem.Recipients.Add                                                      'Insert email address to be sent to
objMailItem.Body = "Hi"                                                         'Text to include in the email
objMailItem.Attachments.Add (CurrentScriptPath & "Test Results.pdf")            'Comment this out if you are not sending an attachement
objMailItem.Subject = "Test"                                                    'Subject line of the email
objMailItem.Send
Set objMailItem = nothing
Set objOutl = nothing
End Function

 

Hardware and Software Requirements

This currently only works with Outlook- you must have Outlook installed on the computer you run the script on

Steps to Implement or Execute Code

1. Put in required email addresses as shown in comments, and then run the script

Additional Information or References

Tested on DIAdem 2015 SP2

 

The 64-bit version of DIAdem 2017 has an object-oriented script interface for sending emails. Details can be found in this topic and also in the related links: http://zone.ni.com/reference/en-XX/help/370858N-01/emailservice/objects/iemailservice_objects_overvi...

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.