Sometimes we need to schedule some mails to be sent to different groups of Jira. For example, for worklog compliance, or similar cases.
For this reason in Jira we usually create Services to do these tasks.
We cannot send mails directly to groups, but with a simple script we can obtain the mail list of members of the Jira groups (or Ldap groups) and use it to send the mail.
We can combine with some pieces of code to operate with the current DATE_TIME
Example of script to start the mail…
import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.CustomFieldType import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.mail.Email import com.atlassian.mail.server.MailServerManager import com.atlassian.mail.server.SMTPMailServer import org.apache.log4j.Category import com.atlassian.jira.user.util.UserUtil import com.atlassian.jira.component.ComponentAccessor; import java.text.SimpleDateFormat import java.sql.Timestamp import java.text.DateFormat import java.util.Date MailServerManager mailServerManager = ComponentAccessor.getMailServerManager() SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer() def bcc = "raulpelaez@mraddon.com"; def groups = ["jira-software-users","jira-core-users"] def groupManager = ComponentAccessor.getGroupManager() def i = 0; while ( i < groups.size()) { def members = groupManager.getUsersInGroup(groups[i]) def j = 0; while ( j < members.size()) { bcc = bcc + "," + members[j].getEmailAddress(); j++ } i++ } Email email = new Email("default<raulpelaez@mraddon.com>") email.setMimeType("text/html") email.setBcc(bcc) email.setSubject("Ethereum will dominate the world!"); def text = "Message content in HTML" email.setBody(text) mailServer.send(email)