diff --git a/cuebot/src/main/java/com/imageworks/spcue/util/CueUtil.java b/cuebot/src/main/java/com/imageworks/spcue/util/CueUtil.java index 990511f47..2a7438f49 100644 --- a/cuebot/src/main/java/com/imageworks/spcue/util/CueUtil.java +++ b/cuebot/src/main/java/com/imageworks/spcue/util/CueUtil.java @@ -35,6 +35,7 @@ import java.util.regex.Pattern; import javax.activation.DataHandler; import javax.activation.DataSource; +import javax.annotation.PostConstruct; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.Session; @@ -47,17 +48,24 @@ import org.apache.log4j.Logger; import org.springframework.core.env.Environment; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import com.imageworks.spcue.LayerInterface; import com.imageworks.spcue.SpcueRuntimeException; import com.imageworks.spcue.dispatcher.Dispatcher; + /** * CueUtil is set of common methods used throughout the application. */ +@Component public final class CueUtil { private static final Logger logger = Logger.getLogger(CueUtil.class); + private static String smtpHost = ""; + @Autowired + private Environment env; /** * Commonly used macros for gigabyte values in KB. @@ -88,6 +96,11 @@ public final class CueUtil { */ public static final int ONE_HOUR = 3600; + @PostConstruct + public void init() { + CueUtil.smtpHost = this.env.getRequiredProperty("smtp_host", String.class); + } + /** * Return true if the given name is formatted as a valid * allocation name. Allocation names should be facility.unique_name. @@ -157,7 +170,7 @@ public static int findChunk(List dependOnFrames, int dependErFrame) { public static void sendmail(String to, String from, String subject, StringBuilder body, Map images) { try { Properties props = System.getProperties(); - props.put("mail.smtp.host", "smtp"); + props.put("mail.smtp.host", CueUtil.smtpHost); Session session = Session.getDefaultInstance(props, null); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); @@ -189,6 +202,8 @@ public static void sendmail(String to, String from, String subject, StringBuilde msg.setContent(mimeMultipart); msg.setHeader("X-Mailer", "OpenCueMailer"); msg.setSentDate(new Date()); + Transport transport = session.getTransport("smtp"); + transport.connect(CueUtil.smtpHost, null, null); Transport.send(msg); } catch (Exception e) { diff --git a/cuebot/src/main/resources/opencue.properties b/cuebot/src/main/resources/opencue.properties index dea35cd30..e64f6e417 100644 --- a/cuebot/src/main/resources/opencue.properties +++ b/cuebot/src/main/resources/opencue.properties @@ -117,3 +117,6 @@ history.archive_jobs_cutoff_hours=72 # Delete down hosts automatically. maintenance.auto_delete_down_hosts=false + +# Set hostname/IP of the smtp host. Will be used for mailing +smtp_host=smtp