Lookup email setting fields in another table

I’m looking for a simple way to manage changes to mail settings in my app, without going back and changing the app in Scriptcase and generating new files every time we need to change mail settings like password, etc.

Therefore, I have created an app based on the following table to update the settings of apps with email settings:

CREATE TABLE `sec_smtp` (
  `friendly_name` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  `server_email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `user_email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `pass_email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `from_email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `port_email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `ssl_email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `format_email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `text_email` text COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

The “friendly_name” is the unique field that is specific to each app that uses the mail function.

Below I have the PHP module “send_mail_message” from the Scriptcase security module where instead of the hardcoded values I will look up the values from my MySql table sec_smtp mentioned above.

/**

  • Send a simple email
    */

// Email parameters
$mail_smtp_server = ‘mail.xxx.com’; // SMTP server name or IP address
$mail_smtp_user = ‘admin@xxx.com’; // SMTP user name
$mail_smtp_pass = ‘password’; // SMTP password
$mail_from = ‘admin@xxx.com’; // From email
$mail_to = [usr_email]; // To email
$mail_message = $param_message;
$mail_subject = {lang_subject_mail}; // Message body
$mail_format = ‘H’; // Message format: (T)ext or (H)tml

// Send email
sc_mail_send($mail_smtp_server,
$mail_smtp_user,
$mail_smtp_pass,
$mail_from,
$mail_to,
$mail_subject,
$mail_message,
$mail_format,
‘’,’’, ‘465’, ‘S’);

if ({sc_mail_ok})
{
sc_alert({lang_mail_sended_ok} );
}
else
{
sc_erro_mensagem({sc_mail_erro});
}

I would really appreciate it very much if someone has or can point to a solution already made.

Thank you! :slightly_smiling_face:

I solved it this way in the PHP-Module “send_mail_message” :

$sql = “SELECT
friendly_name,
server_email,
user_email,
pass_email,
from_email,
port_email,
ssl_email,
format_email,
text_email
FROM
sec_smtp
WHERE
friendly_name=‘app_retrieve_pswd’”;

sc_select(ds, $sql);

/**

  • Send a simple email
    */

// Email parameters
$mail_smtp_server = {ds}->fields[‘server_email’]; // SMTP server name or IP address
$mail_smtp_user = {ds}->fields[‘user_email’]; // SMTP user name
$mail_smtp_pass = {ds}->fields[‘pass_email’]; // SMTP password
$mail_from = {ds}->fields[‘from_email’]; // From email
$mail_to = [usr_email]; // To email
$mail_message = $param_message;
$mail_subject = {lang_subject_mail}; // Message body
$mail_format = {ds}->fields[‘format_email’]; // Message format: (T)ext or (H)tml

// Send email
sc_mail_send($mail_smtp_server,
$mail_smtp_user,
$mail_smtp_pass,
$mail_from,
$mail_to,
$mail_subject,
$mail_message,
$mail_format,
‘’,’’, ‘465’, ‘S’);

if ({sc_mail_ok})
{
sc_alert({lang_mail_sended_ok} );
}
else
{
sc_erro_mensagem({sc_mail_erro});
}