Search code examples
jira

Extract Server name from JIRA


I would like to get the server name(pop/Imap mail server) from JIRA.

I searched the JIRA API and I tried in few ways, but could not do it.

How I can do it?


Solution

  • To get this, you will need to first get an instance of the MailServerManager from JIRA, the following Groovy fragment shows how to accomplish this:

    import com.atlassian.jira.ComponentManager
    import com.atlassian.mail.server.MailServerManager
    
    componentManager = ComponentManager.getInstance()
    mailServerManager = componentManager.getMailServerManager()
    

    To get the Hostname of the SMTP Server for the default SMTPMailServer, the following Groovy fragment shows how:

    import com.atlassian.jira.ComponentManager
    import com.atlassian.mail.server.MailServerManager
    
    componentManager = ComponentManager.getInstance()
    mailServerManager = componentManager.getMailServerManager()
    mailServer = mailServerManager.getDefaultSMTPMailServer()
    return mailServer.getHostname()
    

    Getting the hostname of the default POPMailServer is done as followed:

    import com.atlassian.jira.ComponentManager
    import com.atlassian.mail.server.MailServerManager
    import com.atlassian.mail.server.SMTPMailServer
    
    componentManager = ComponentManager.getInstance()
    mailServerManager = componentManager.getMailServerManager()
    mailServer = mailServerManager.getDefaultPopMailServer()
    return mailServer.getHostname()
    

    The classes in the JIRA API you will want to reference are: