TN AppSvr200 Send an Email from an Application Server script
Description
This article from InSource shows...How to Send an E-mail from an Application Server script
- Author: Mike Viteri
- Published: 05/19/2016
- Applies to: Application Server 2.1 or greater
Details
This scripts below shows how to send an email from Application Server.
Some of the variables are local. Some of the variables are memory attributes inside of an Application Server object.
The variables that are memory attributes are below(All Strings). You will have to set the Initial Values.
EmailBodyText - This is what you want to me in the body of your email
Emailfrom - The email address you want it to show from
EmailSMTPServer - Your Email Server
EmailSubject - What the subject line will say.
EmailTo - The email address it will be sent to.
EmailTrigger - will run the email script.
This script gets triggered when the memory tag EmailTrigger goes true.
The full script is below and can be put into an Application Server script.
---------------------------------------Script Start----------------------------------------------------------------------
'initialize local variables
Dim SmtpMailClient as System.Net.Mail.SmtpClient;
Dim sMailText as String;
Dim sMailSubject as String;
'reset the script trigger first
Me.EMailTrigger = False;
SmtpMailClient = new System.Net.Mail.SmtpClient();
'set the subjet variable
sMailSubject = Me.EmailSubject;
'set them message text variable
sMailText = me.EmailBodyText;
'enable SSL IF the server requires
SmtpMailClient.EnableSsl=True;
'set the SMTP hostname
SmtpMailClient.Host=me.EmailSMTPServer;
'Set credentials IF required by the server
SmtpMailClient.Credentials = New System.Net.NetworkCredential ("Your email","Your Password");
'Send the email message (FromAddress,ToAddress,SubjectLine, Body)
SmtpMailClient.Send( me.EmailFrom, me.EmailTo, sMailSubject , sMailText);
---------------------------------------Script End----------------------------------------------------------------------
Where it says YourEmail & YourPassword you will need to fill these out if your E-mail server requires authentication.