Skip to main content

Creating a Mail Message

Next, we create a MailMessage object and fill in its From, To, and Subject attributes.

Note that we specify the “To” address by calling a method, Msg.To.Insert, rather than by setting a property directly. This enables a message to be sent to multiple recipients, by calling this method repeatedly.

(Again, to try this on your computer, replace "**Address**" with your own e-mail address.)

—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"
}
FeedbackOpens in a new tab