Sandbox: Outlook to Jira

In the life of every developer there is a time for support and maintenance. So in my life too. I love Jira as an issue tracking tool. Outlook is not a bad corporate email client neither. :) Thus inspired by this article and powerful Jira RESTfull API. I decided to spend few hours of my spare time to do something useful.

The idea was to have a button in the Outlook so when you click, it would create a Jira ticket based upon the current email and modify the message by putting there a link to the created ticket.

The final result of this you may see below


So by using VSTO and Jira API it was quite easy to achieve it. The article above mentioned is describing all steps required to create a VSTO project in Visual Studio. I'll just focus on the API been used.

Basically to create an issue in Jira using API you should have an account and check if it is allowed to use the remote API in your instance of Jira and do the call it-self.

In my case I wanted that issue to be created in the specific project, assigned to me and body of the email message is copied to the description of the issue and subject is copied to the issue's summary with few additions. I created a wrapper class to encapsulate the call to the service and number of DTOs to abstract away the JSON string. 
               JiraService js = new JiraService(new Uri(Settings.Default.JiraApiUrl), Settings.Default.JiraUserName, Settings.Default.JiraPassword);
                CreateIssueResponseObject ro = js.CreateIssue(new JiraDTO.CreateIssueRequestObject()
                {
                    Fields = new JiraDTO.FieldsObject()
                    {
                        Project = new JiraDTO.ProjectObject()
                        {
                            Key = Settings.Default.JiraDestinationProjectKey
                        },
                        Summary = String.Format("Support request on {0} from {1}", messageDetails.CurrentMessage.Subject.Replace("RE:", String.Empty).Trim(), messageDetails.CurrentMessage.To.Trim()),
                        Description = String.Format("Support request from {0} on\n\n{1}", messageDetails.CurrentMessage.To, messageDetails.CurrentMessage.Body.Trim()),
                        IssueType = new JiraDTO.IssueTypeObject()
                        {
                            Name = Settings.Default.JiraDestiantionIssueType
                        },
                        Assignee = new UserObject()
                        {
                            Name = Settings.Default.JiraUserName
                        }
                    }
                });

I used the Newton.Json library to do the serialization/deserialization of the transfer objects. Dependency is managed by NuGet. So as you can see the call is very simple. The result object of type CreateIssueResponseObject contains the Jira issue key.


To modify the contents of the message there is a property Outlook.Inspector.CurrentItem which while you have your email windows opened is the instance of Outlook.MailItemOutlook.MailItem has two properties representing the body of the message: Body for text and HtmlBody for HTML content. Both properties are writable so you may change them.

On error Jira API returns a non-200 HTTP status code, so it's better to catch the WebException to have the error details in the JSON response content.
            catch (WebException ex)
            {
                System.Windows.Forms.MessageBox.Show(String.Format("Error {0}\n{1}", ex.Message, ex.Response != null ? new StreamReader(ex.Response.GetResponseStream()).ReadToEnd() : String.Empty), 
                    "Error Message", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
This add-on is very easy to publish and deploy using OneClick installer.

The source code is available at github.

Popular posts from this blog

Debug: WER and WinDbg

Dev: PlantUML + VS Code + GitLab

BigData intro at Ciklum's Speakers' Corner