Article
· Mar 14, 2017 2m read

Sending Email notifications "On behalf of"

A feature I recently used in working on ISC internal applications is the ability to send emails on behalf of someone. This is useful when generating system notifications from an application when you want some of them to show up as being from a specific person, perhaps posting comments on a work ticket.

In my case I was updating our facilities work order system for tracking requests. Normally all notification emails are sent from the same noreply email address. I wanted to change that so comments added from the original requester would show up as being from them and stand out. 

If you're using the %Net.MailMessage class you can do this by setting the "From" and "Sender" properties. These are standard to the RFC defining sftp email and should be included in any implementation. 

For example:

    s Mailer = ##class(%Net.SMTP).%New()
    Mailer.smtpserver = "<server address>"
    Msg = ##class(%Net.MailMessage).%New()

    Msg.From = owner.Email
    Msg.Sender = "application-noreply@intersystems.com"

    Msg.To.Insert(recipient.Email)
    Msg.Subject = "Notification Email"
    Msg.TextData.Write(body)

     set ok = Mailer.Send(Msg)
    do Mailer.%Close()
    do Msg.%Close()

 

The From property is who the email is ultimately from, and the Sender property is an optional middleman who handles the message. The email generated in the above example will show up as 

"From application-noreply@intersystems.com on behalf of <owner.Email>"

This will still be handled by any outlook rules for "emails from 'application-noreply@intersystems.com'". Or can be separated out by a custom rule that looks for "From: <owner.Email>" in the message header.

Discussion (2)0
Log in or sign up to continue