Sending the Message
Now all we have to do is fill in the message text, using the MessageText argument passed into the method.
To send the message, we call the Send method of the mail server object, passing it the message object.
—Utils.SendEmail—
Utils.SendEmail
ClassMethod SendEmail(Address As %String, MessageText As %String)
{
// Create an SMTP object and connect to a server
Set Mailer = ##class(%Net.SMTP).%New()
// Fill in the name of your mail server
Set Mailer.smtpserver = "**Server**"
// Create a Message object and fill in From, To, Subject
Set Msg = ##class(%Net.MailMessage).%New()
Set Msg.From="**Address**"
Do Msg.To.Insert(Address)
Set Msg.Subject = "Theater Tickets"
// Add message content
Do Msg.TextData.Write(MessageText)
// Send the message and close objects
Do Mailer.Send(Msg)
Quit
}