Email users listed in a database...

  • 13 October 2005
  • 2 replies
  • 3 views

Badge +1
Email users listed in a database...

I have a need to email several users, who are likely to change at any time, at the end of one of my K2 processes to inform them that the process is complete and that they need to action some non-K2 business processes.

I would like to have these email addresses stored in a database and pulled down into K2 at the time of the event. Then, I would like to loop through the DB result set and email to the returned addresses.

I don't imagine that this is too difficult, but I have not yet been able to get it to work.

Having worked on this, on and off, for several weeks now, I'm putting it out there to see if anyone else has developed anything similar.

Any assistance here would be greatly appreciated.

Just to note, I understand the principal of what I'm trying to do, I just can't manage to get it working in K2 using a default client or server event.

Thanks a lot!

Andrew.

2 replies

Badge +7
Hi Andrew,

You can perform the retrieval of email addresses and sending of the emails using a Default Server event. Obviously, there can be more than one way of achieving this. Short of providing you the code to this, I have listed down the steps of a simple way you could get this done.

1. Add a Server Mail Event template
In the last activity of your process, add a Server Mail event and complete the wizard with the email message you would like to send out. Depending on your process design, you may need to add an Activity for this purpose.

2. Customize the Server Mail Event code
The next step would involve jumping into the code view of the Server Mail event (in K2.net Studio). You should add some ADO.NET code at the top of the SMTPFunction code to retrieve the email addys from the DB. Once you have the dataset, you could easily iterate through each record and have the email sent for each email address by assigning the value to the objMsg.To property.

Alternatively, you could consider concantenating the email addresses (eg. tom@here.com;bob@here.com) and send out one email as opposed to individual emails.

Hope this helps.
Badge +1
Hi Samuel,

Thanks so much for that, it's saved me a lot of frustration.

I know what you said seems fairly basic, but you put it in a way that suddenly made a whole lot of sense! So thank you very much!

Kind regards,

Andrew.

Reply