Отправить индивидуальный адрес электронной почты - malikovalibek/groovyForJira GitHub Wiki
Обзор В этом фрагменте показано, как отправить собственное электронное письмо. Вы можете использовать этот метод в любом скрипте, предназначенном для отправки электронной почты.
пример Я хочу отправлять электронное письмо, когда проблема переходит из статуса "Выполняется" на "Готово", чтобы сообщить клиенту о статусе проблемы. Я могу использовать этот фрагмент внутри сценария пост-функции.
Хорошо знать Необходимо включить сервер исходящей почты. Необходимо настроить почтовый сервер SMTP. Требования JiraJira (7,7 - 8,6)
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.mail.Email import com.atlassian.jira.mail.settings.MailSettings import com.atlassian.mail.MailException import org.apache.log4j.Level import org.apache.log4j.Logger
def log = Logger.getLogger(getClass()) log.setLevel(Level.DEBUG)
String sendEmail(String emailAddr, String subject, String body) { // Stop emails being sent if the outgoing mail server gets disabled (useful if you start a script sending emails and need to stop it) def mailSettings = ComponentAccessor.getComponent(MailSettings) if (mailSettings?.send()?.disabled) { return "Your outgoing mail server has been disabled" }
def mailServer = ComponentAccessor.mailServerManager.defaultSMTPMailServer
if (!mailServer) {
log.debug("Your mail server Object is Null, make sure to set the SMTP Mail Server Settings Correctly on your Server")
return "Failed to Send Mail. No SMTP Mail Server Defined"
}
def email = new Email(emailAddr)
email.setMimeType("text/html")
email.setSubject(subject)
email.setBody(body)
try {
mailServer.send(email)
log.debug("Mail sent")
"Success"
} catch (MailException e) {
log.debug("Send mail failed with error: ${e.message}")
"Failed to Send Mail, Check Logs for error"
}
}
sendEmail('[email protected]', '', '')