Search code examples
python-2.7smtpjirajira-rest-apipython-jira

JIRA API Send Email


I'm currently using the python JIRA to create issues. I want to be able to send an email to specific email addresses after the issue is created. Here is the solution I tried but it doesn't to work.

jira = JIRA(options,basic_auth=('[email protected]','password'))
jira.email_user('[email protected]', 'test email body', title='JIRA Notification')

But the request to email_user gives me a 404 error. "Oops, you've found a dead link". Anyone know an alternate way to send a custom email to a specified email address when a jira issue is created? I would prefer to do this through JIRA Rest API.


Solution

  • In case anyone else has this issue, here is how you can send a custom email using the JIRA rest api (in python):

    import requests
    
    url = "https://jiraserver.atlassian.net/rest/api/2/issue/{issue number or key}/notify"
    
    notify_data = {
            "subject": "Duis eu justo eget augue iaculis fermentum.",
            "textBody": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
            "htmlBody": "Lorem ipsum <strong>dolor</strong> sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
            "to": {
                "users": [
                    {
                        "name": "JIRA user"}] #Make sure you set permission for receiving notifications from self in your profile if you use same user you are logged in as"
            },
    
        }
    
    requests.post(url,auth=('jira username','jira password'), json=notify_data)