K2 BlackPearl SMTP configuration
I recently suffered a few gotchas while trying to add a new SMTP server to use for our emails, and figured that it would be a good topic to write a blog about. All of the steps discussed might not be applicable to every situation, but this article should serve as a good point of reference when you get stuck.
Lets start with the basics.
K2 Automated Testing Software
BenchQA allows full test automation of K2, including fully automated K2 SmartForms and K2 Workflow testing. It promotes test driven development for K2 and ensures continued quality assurance for K2 solutions. Easily apply changes to test cases to accommodate changes to K2 apps and ensure all apps are regression tested to avoid defects and assure continuous quality.
We create a new workflow, and add a mail event to it. We then follow the configuration wizard, as outlined in the blog article located at here, and Bob is your uncle. But what if you want Steve as an uncle, and not Bob? What I mean is that your emails should now send succesfully, if the default setup was correct, but what if it wasn’t. Lets discuss the steps required to add a new SMTP server and send your emails through that server. For this blog post we will use gmail as our SMTP server. I have created a simple workflow with an email event already, which is pictured below.
To add a new SMTP server we first open the Connection String Editor, located at C:Program Files (x86)K2 blackpearlHost ServerBinConnectionStringEditor.exe. We then press the + icon, and select SMTP from the dropdown.
The Connection String Editor will now prompt us for the identity of the connection string. It is important that we add the email address we will use as the ‘from’ field for our emails here. In this case I have already created a gmail account with the following address: firstname.lastname@example.org, which we will use to send our emails from. I will therefore enter this email in the prompt.
The new connection string will now be added to the list on the left. We select the new connection string from the list, and then complete the parameters for this connection on the right. We then press the save button and press ‘Yes’ when prompted to save the new values to the database. The screen shot below indicates the required parameters as appropriate to the google SMTP server
Now lets return to our workflow and modify it to make use of our newly added SMTP Server. First we need to open the mail event we added earlier. When we open the mail event we will check the ‘Run this wizard in Advanced Mode’ checkbox to enable us to specify our newly added server, as indicated in the screen shot below.
We then press next and complete the normal fields as we usually would do. Please note that the From field here needs to be the identity for the SMTP connection we added earlier, in this case email@example.com. This from field will be used to locate the correct connection string from the K2 configuration when the mail is sent. For this example I will send the mail to myself, just to see whether it works. The screen shot below shows the completed form.
We now press next, which will prompt us for the Message Body, which we can complete according to our hearts desire. Pressing next again will brings us to the Attachments we wish to add. One more Next brings us to the all-important choice of which SMTP server we would like to use. Note that this setting is not available unless the wizard is run in ‘Advanced Mode’. Seeing that we will be using gmail as our smtp server we will enter the gmail smtp server details into the text box, as indicated below.
Now we can finish the wizard, and deploy our workflow.
Lets test it out to see whether it works. Lets open our K2 workspace, and open the management console. Browse to the TestEmail process we just modified, and select the instances, as indicated below. Then press the Start New button.
Once we press on start new it will prompt us for various parameters which we can ignore for now. Just press start. A new instance of the process will be started and displayed with a status of ‘Running’. Just wait a few seconds and refresh. Wonderful, we have just sent an email, which didn’t work, as indicated by the big red ‘Error’ status displayed to us. Lets hover over the Error to see what happened.
‘There is no connection string for the destination email address firstname.lastname@example.org’. That is a pity. I thought we just added it. Ok, I admit, I knew this was going to be the result, but I thought I’d keep you intrigued. Now you will have to wait for my next article to see how to fix it. You can find the answer in part 2 of this article, along with a few other tips on how to resolve some other issues when trying to send an email through a SMTP server.