Email utility methods
In addition to the Email and EmailContact classes, Guidewire
also provides a set of static utility methods in the gw.api.email.EmailUtil class for
generating and sending emails from Gosu, for example:
gw.api.email.EmailUtil.sendEmailWithBody( KeyableBean entity, Email email )
gw.api.email.EmailUtil.sendEmailWithBody( KeyableBean entity,
Contact to,
Contact from,
String subject,
String body )
gw.api.email.EmailUtil.sendEmailWithBody( KeyableBean entity,
String toEmailAddress,
String toName,
String fromEmailAddress,
String fromName,
String subject,
String body )
These methods all take an entity as the first parameter. This parameter can be
null. However, if specified, use the application entity to
which this email is related, such as a specific policy or activity. PolicyCenter uses this parameter only while processing the
email for transmission. See Email transmission.
Emails that use an Email object
One variation of the sendEmailWithBody method requires that you create a gw.api.email.Email entity, and then define its properties to build the Email entity. For example:
...
var testEmail : gw.api.email.Email
testEmail.Body = "This is a test."
testEmail.Subject = "Test"
...
gw.api.email.EmailUtil.sendEmailWithBody( thisClaim, testEmail )
You can also attach multiple To, CC, and BCC addresses to the email.
Emails that use Contact objects
Another variation of the sendEmailWithBody method uses
Contact objects for the to and
from parameters. In Gosu, you can obtain
Contact objects from various places. For example, in a
policy rule, to send an email from an
insurance company employee to the insured, do the following:
- Set the to parameter to
Policy.insured. - Set
fromtoPolicy.AssignedUser.Contact.
The following Gosu example generates an email from the current assigned user to that user’s supervisor:
gw.api.email.EmailUtil.sendEmailWithBody(thisPolicy, thisPolicy.AssignedGroup.Supervisor.Contact,
thisPolicy.AssignedUser.Contact, "A policy got a PolicyValid event", "This is the text." )
Emails that use an email address
Use the following variation of the sendMailWithBody method if you do not have a full Contact object for a
recipient or sender. It is possible that another application dynamically generated the Contact object, providing an
incomplete version of the object. The sendMailWithBody method uses a name and email address instead of entire
Contact records and does not require that you have access to a Contact record.
In the following example, all arguments are String objects:
gw.api.email.EmailUtil.sendEmailWithBody( Entity, toName, toEmail, fromName, fromEmail, subject, body)