Skip to main content

Connecting to the Mail Server

Next, we need to add the code to connect to a mail server. To do this, we create an instance of SMTP object, which is provided in the standard Caché %Library package. We also need to identify which server to use, by setting the smtpserver property.

(To try this on your computer, replace "**Server**" with the name of your local e-mail server. If you are not sure what its name is, try looking at the set up for your e-mail program to find the setting for the outgoing mail or smtp server.)

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