diff --git a/cuebot/src/main/java/com/imageworks/spcue/service/EmailSupport.java b/cuebot/src/main/java/com/imageworks/spcue/service/EmailSupport.java index a96826782..5154e60f7 100644 --- a/cuebot/src/main/java/com/imageworks/spcue/service/EmailSupport.java +++ b/cuebot/src/main/java/com/imageworks/spcue/service/EmailSupport.java @@ -37,6 +37,8 @@ import org.apache.velocity.app.VelocityEngine; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.mail.MailException; import org.springframework.mail.MailSender; import org.springframework.mail.SimpleMailMessage; @@ -59,19 +61,21 @@ public class EmailSupport { private MailSender mailSender; private JobManager jobManager; - private Properties opencueProperties; + @Autowired + private Environment env; + + private String emailDomain; + private String emailFromAddress; + private String[] emailCcAddresses; private Map imageMap; private static final Logger logger = LogManager.getLogger(EmailSupport.class); public EmailSupport() { - - /* - * The OpenCue configuration file which we need to find the email template. - */ - opencueProperties = getOpenCueProperties(); - + this.emailDomain = env.getProperty("email.domain", "opencue.io"); + this.emailFromAddress = env.getProperty("email.from.address", "opencue-noreply@opencue.io"); + this.emailCcAddresses = env.getProperty("email.cc.addresses", "").split(","); } private static void loadImage(Map map, String path) { @@ -141,9 +145,9 @@ private static void loadImage(Map map, String path) { public void reportLaunchError(JobSpec spec, Throwable t) { SimpleMailMessage msg = new SimpleMailMessage(); - msg.setTo(String.format("%s@imageworks.com", spec.getUser())); - msg.setFrom("middle-tier@imageworks.com"); - msg.setCc("middle-tier@imageworks.com"); + msg.setTo(String.format("%s@%s", spec.getUser(), this.emailDomain)); + msg.setFrom(this.emailFromAddress); + msg.setCc(this.emailCcAddresses); msg.setSubject("Failed to launch OpenCue job."); StringBuilder sb = new StringBuilder(131072); @@ -175,7 +179,7 @@ public void reportJobComment(JobInterface job, CommentDetail c, String[] emails) SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(emails); - msg.setFrom("opencue-noreply@imageworks.com"); + msg.setFrom(this.emailFromAddress); msg.setSubject("New comment on " + job.getName()); StringBuilder sb = new StringBuilder(8096); @@ -197,25 +201,6 @@ public void sendMessage(SimpleMailMessage message) { } } - public Properties getOpenCueProperties() { - - // get the input stream of the properties file - InputStream in = EmailSupport.class.getClassLoader() - .getResourceAsStream("opencue.properties"); - - Properties props = new java.util.Properties(); - try { - props.load(in); - } catch (IOException e) { - props = new Properties(); - props.setProperty( "resource.loader", "file" ); - props.setProperty("class.resource.loader.class", - "org.apache.velocity.runtime.resource.loader.FileResourceLoader" ); - props.setProperty("file.resource.loader.path", "/opt/opencue/webapps/spcue"); - } - return props; - } - public void sendShutdownEmail(JobInterface job) { JobDetail d = jobManager.getJobDetail(job.getJobId()); @@ -294,8 +279,6 @@ public void sendShutdownEmail(JobInterface job) { subject = status + subject; - String from = "opencue-noreply@imageworks.com"; - BufferedWriter output = null; File file = null; if (shouldCreateFile){ @@ -328,7 +311,7 @@ public void sendShutdownEmail(JobInterface job) { for (String email : d.email.split(",")) { try { - CueUtil.sendmail(email, from, subject, new StringBuilder(w.toString()), imageMap, file); + CueUtil.sendmail(email, this.emailFromAddress, subject, new StringBuilder(w.toString()), imageMap, file); } catch (Exception e) { // just log and eat if the mail server is down or something // of that nature. diff --git a/cuebot/src/test/resources/opencue.properties b/cuebot/src/test/resources/opencue.properties index 10516f881..f62a12532 100644 --- a/cuebot/src/test/resources/opencue.properties +++ b/cuebot/src/test/resources/opencue.properties @@ -1,6 +1,14 @@ cue.proxy = tcp -h cuetest01-vm -p 9019 -t 10000:tcp -h cuetest02-vm -p 9019 -t 10000:tcp -h cuetest03-vm -p 9019 -t 10000 spring.velocity.checkTemplateLocation=false +# A domain to attach to usernames to send job completition emails +# eg: job_user=jon -> email-to: jon@opencue.io +email.domain=opencue.io +# An email address to use as From for cuebot emails +email.from.address=opencue-noreply@opencue.io +# A comma-separated list of emails to be cc'ed on maintenance communications +email.cc.addresses=dev-team@opencue.io + grpc.cue_port=8453 grpc.rqd_server_port=${CUEBOT_GRPC_RQD_SERVER_PORT:50051} grpc.max_message_bytes=104857600