Regarding the trigger I am partial to what @victordcq suggested and that's how I like to do things when I have to shell out. Whenever I have process that Vision\Ignition starts, but cannot not directly do (but instead calls out to an external service like emailing does, or SFTP'ing a with a batch file for example) it's nice to have a database table keep track of what jobs those are.
For you, you might want a table like
CREATE TABLE emailJobs(
id int not null primary key,
newValue (if there's a column you want to reference in the email, put it here),
newValue2 (if there's a second column that helps put form the subject or body of the email),
newValue3(and so on for any other Params you may want to grab to help form your email),
tsAttempted datetime default NULL);
Then, somewhere in your application, you must have something like a UPDATE originalTable SET someColumn=? WHERE id=?
where hopefully you can tell when a row that you want emailed about is running.
When you see a row that you know needs to be updated in your previous update statement, then INSERT into emailJobs.
Then I would create gateway timer script that once every few minutes looks at your emailJobs
database table where the tsAttempted
is NULL, and then tries to run that particular email job, and updates the table afterwards.
I believe system.net.sendEmail does not give you confirmation or an error in your script and it really can't because it has to call out to your SMTP server can take a while, etc so any success / errors go straight to the gateway as I recall. However, after you attempt your email, you can then update your tsAttempted
column with the time, so if anything does go awry you at least know what time frame to look at in your logs. If I am wrong though, you could always add another column to emailJobs
to record your result.
emailJobs
now basically acts like a queue for you that will survive GW restarts. SELECT * FROM emailJobs WHERE tsAttempted IS NULL ORDER BY id ASC
would give the next job and I would use that in my GW script.