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