Skip to content

Commit

Permalink
Set smtp_host as env variable (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
akim-ruslanov authored Apr 1, 2022
1 parent d899b71 commit 6993baa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cuebot/src/main/java/com/imageworks/spcue/util/CueUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -157,7 +170,7 @@ public static int findChunk(List<Integer> dependOnFrames, int dependErFrame) {
public static void sendmail(String to, String from, String subject, StringBuilder body, Map<String, byte[]> 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));
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions cuebot/src/main/resources/opencue.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6993baa

Please sign in to comment.