Typically we use a constant to derive the server environment. Constants are stored and persisted per environment, so you would just need to set it up once in the cloud.
If the mail settings are something that could change in the future, you might consider storing the mail server config as your constant rather than just an environment flag.
You could also use the community commons GetApplicationUrl. Since Mendix is consistent with the names of the acceptance and test environments you could check with the contain function in which environment you are. We use this all the time to changes settings depending on environment.
Regards,
Ronald
For us the most reliable way to detect studio is the presense of the Studio Console. We created a java action that returns true if com.mendix.logging.impl.subscribers.TcpJsonLinesSubscriber is active.
package _sysutils.actions;
import java.util.Map;
import java.util.Set;
import com.mendix.core.Core;
import com.mendix.logging.ILogNode;
import com.mendix.logging.LogLevel;
import com.mendix.logging.LogSubscriber;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.UserAction;
public class IsStudioConsoleLoggerActive extends UserAction<java.lang.Boolean>
{
public IsStudioConsoleLoggerActive(IContext context)
{
super(context);
}
@java.lang.Override
public java.lang.Boolean executeAction() throws Exception
{
// BEGIN USER CODE
final ILogNode coreLogger = Core.getLogger(CORE_LOGGER);
Map<LogSubscriber, LogLevel> subscribers = coreLogger.getSubscribers();
boolean res = false;
for (LogSubscriber logSubscriber : subscribers.keySet()) {
final String className = logSubscriber.getClass().getName();
final boolean isKnownStudioConsole = KNOWN_CONSOLE_SUBSCRIBERS.contains(className);
coreLogger
.info(
"Subscriber: " + className + " " + logSubscriber.getName()
+ " isKnownStudioConsole:" + isKnownStudioConsole);
// do not break, log all
res |= isKnownStudioConsole;
}
return res;
// END USER CODE
}
/**
* Returns a string representation of this action
* @return a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "IsStudioConsoleLoggerActive";
}
// BEGIN EXTRA CODE
private static final String CORE_LOGGER = "Core";
/** Seen in Mx 10.24 */
private static final String TCP_JSON_LINES_SUBSCRIBER =
"com.mendix.logging.impl.subscribers.TcpJsonLinesSubscriber";
private static final Set<String> KNOWN_CONSOLE_SUBSCRIBERS = Set.of(TCP_JSON_LINES_SUBSCRIBER);
// END EXTRA CODE
}