Version 22.50.4: Oct 20, 2022 Code refactoring in email sending.

This commit is contained in:
acanas 2022-10-20 10:05:24 +02:00
parent a7c0f6bc46
commit 92559fd9a9
5 changed files with 44 additions and 57 deletions

View File

@ -605,10 +605,11 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
TODO: Attach pdf files in multimedia.
*/
#define Log_PLATFORM_VERSION "SWAD 22.50.3 (2022-10-19)"
#define Log_PLATFORM_VERSION "SWAD 22.50.4 (2022-10-20)"
#define CSS_FILE "swad22.49.4.css"
#define JS_FILE "swad22.49.js"
/*
Version 22.50.4: Oct 20, 2022 Code refactoring in email sending. (333438 lines)
Version 22.50.3: Oct 19, 2022 Fixed bug in keys when playing matches. (333456 lines)
Version 22.50.2: Oct 19, 2022 Code refactoring related to dates. (333456 lines)
Version 22.50.1: Oct 19, 2022 Code refactoring related to dates. (333332 lines)

View File

@ -1431,10 +1431,6 @@ bool Mai_SendMailMsgToConfirmEmail (void)
extern const char *Txt_There_was_a_problem_sending_an_email_automatically;
char FileNameMail[PATH_MAX + 1];
FILE *FileMail;
char Command[2048 +
Cfg_MAX_BYTES_SMTP_PASSWORD +
Cns_MAX_BYTES_EMAIL_ADDRESS +
PATH_MAX]; // Command to execute for sending an email
int ReturnCode;
/***** Create temporary file for mail content *****/
@ -1460,25 +1456,13 @@ bool Mai_SendMailMsgToConfirmEmail (void)
fclose (FileMail);
/***** Call the script to send an email *****/
snprintf (Command,sizeof (Command),
"%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"[%s] %s\" \"%s\"",
Cfg_COMMAND_SEND_AUTOMATIC_EMAIL,
Cfg_AUTOMATIC_EMAIL_SMTP_SERVER,
Cfg_AUTOMATIC_EMAIL_SMTP_PORT,
Cfg_AUTOMATIC_EMAIL_FROM,
Gbl.Config.SMTPPassword,
Gbl.Usrs.Me.UsrDat.Email,
Cfg_PLATFORM_SHORT_NAME,Txt_Confirmation_of_your_email_NO_HTML,
FileNameMail);
ReturnCode = system (Command);
if (ReturnCode == -1)
Err_ShowErrorAndExit ("Error when running script to send email.");
ReturnCode = Mai_SendMailMsg (FileNameMail,
Txt_Confirmation_of_your_email_NO_HTML);
/***** Remove temporary file *****/
unlink (FileNameMail);
/***** Write message depending on return code *****/
ReturnCode = WEXITSTATUS(ReturnCode);
switch (ReturnCode)
{
case 0: // Message sent successfully
@ -1705,3 +1689,36 @@ static void Mai_EditingMailDomainDestructor (void)
Mai_EditingMai = NULL;
}
}
/*****************************************************************************/
/***************************** Send mail message *****************************/
/*****************************************************************************/
// Return 0 on success
// Return != 0 on error
int Mai_SendMailMsg (char FileNameMail[PATH_MAX + 1],const char *Subject)
{
char Command[2048 +
Cfg_MAX_BYTES_SMTP_PASSWORD +
Cns_MAX_BYTES_EMAIL_ADDRESS +
PATH_MAX]; // Command to execute for sending an email
int ReturnCode;
/***** Call the script to send an email *****/
snprintf (Command,sizeof (Command),
"%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"[%s] %s\" \"%s\"",
Cfg_COMMAND_SEND_AUTOMATIC_EMAIL,
Cfg_AUTOMATIC_EMAIL_SMTP_SERVER,
Cfg_AUTOMATIC_EMAIL_SMTP_PORT,
Cfg_AUTOMATIC_EMAIL_FROM,
Gbl.Config.SMTPPassword,
Gbl.Usrs.Me.UsrDat.Email,
Cfg_PLATFORM_SHORT_NAME,Subject,
FileNameMail);
ReturnCode = system (Command);
if (ReturnCode == -1) // The value returned is -1 on error
Err_ShowErrorAndExit ("Error when running script to send email.");
/* The exit code of the command will be WEXITSTATUS (ReturnCode) */
return WEXITSTATUS (ReturnCode);
}

View File

@ -100,4 +100,6 @@ void Mai_WriteFootNoteEMail (FILE *FileMail,Lan_Language_t Language);
bool Mai_ICanSeeOtherUsrEmail (const struct Usr_Data *UsrDat);
int Mai_SendMailMsg (char FileNameMail[PATH_MAX + 1],const char *Subject);
#endif

View File

@ -1275,10 +1275,6 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct Usr_Data *ToUsrDat,unsig
char ForumName[For_MAX_BYTES_FORUM_NAME + 1];
char FileNameMail[PATH_MAX + 1];
FILE *FileMail;
char Command[2048 +
Cfg_MAX_BYTES_SMTP_PASSWORD +
Cns_MAX_BYTES_EMAIL_ADDRESS +
PATH_MAX]; // Command to execute for sending an email
int ReturnCode;
/***** Return 0 notifications and 0 mails when error *****/
@ -1419,26 +1415,13 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct Usr_Data *ToUsrDat,unsig
fclose (FileMail);
/***** Call the command to send an email *****/
snprintf (Command,sizeof (Command),
"%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"[%s] %s\" \"%s\"",
Cfg_COMMAND_SEND_AUTOMATIC_EMAIL,
Cfg_AUTOMATIC_EMAIL_SMTP_SERVER,
Cfg_AUTOMATIC_EMAIL_SMTP_PORT,
Cfg_AUTOMATIC_EMAIL_FROM,
Gbl.Config.SMTPPassword,
ToUsrDat->Email,
Cfg_PLATFORM_SHORT_NAME,
Txt_Notifications_NO_HTML[ToUsrLanguage],
FileNameMail);
ReturnCode = system (Command);
if (ReturnCode == -1)
Err_ShowErrorAndExit ("Error when running script to send email.");
ReturnCode = Mai_SendMailMsg (FileNameMail,
Txt_Notifications_NO_HTML[ToUsrLanguage]);
/***** Remove temporary file *****/
unlink (FileNameMail);
/***** Update number of notifications, number of mails and statistics *****/
ReturnCode = WEXITSTATUS(ReturnCode);
if (ReturnCode == 0) // Message sent successfully
{
*NumNotif = NumNtfs;

View File

@ -404,10 +404,6 @@ int Pwd_SendNewPasswordByEmail (char NewRandomPlainPassword[Pwd_MAX_BYTES_PLAIN_
extern const char *Txt_New_password_NO_HTML[1 + Lan_NUM_LANGUAGES];
char FileNameMail[PATH_MAX + 1];
FILE *FileMail;
char Command[2048 +
Cfg_MAX_BYTES_SMTP_PASSWORD +
Cns_MAX_BYTES_EMAIL_ADDRESS +
PATH_MAX]; // Command to execute for sending an email
int ReturnCode;
/***** Create temporary file for mail content *****/
@ -432,26 +428,14 @@ int Pwd_SendNewPasswordByEmail (char NewRandomPlainPassword[Pwd_MAX_BYTES_PLAIN_
fclose (FileMail);
/***** Call the script to send an email *****/
snprintf (Command,sizeof (Command),
"%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"[%s] %s\" \"%s\"",
Cfg_COMMAND_SEND_AUTOMATIC_EMAIL,
Cfg_AUTOMATIC_EMAIL_SMTP_SERVER,
Cfg_AUTOMATIC_EMAIL_SMTP_PORT,
Cfg_AUTOMATIC_EMAIL_FROM,
Gbl.Config.SMTPPassword,
Gbl.Usrs.Me.UsrDat.Email,
Cfg_PLATFORM_SHORT_NAME,
Txt_New_password_NO_HTML[Gbl.Usrs.Me.UsrDat.Prefs.Language],
FileNameMail);
ReturnCode = system (Command);
if (ReturnCode == -1)
Err_ShowErrorAndExit ("Error when running script to send email.");
ReturnCode = Mai_SendMailMsg (FileNameMail,
Txt_New_password_NO_HTML[Gbl.Usrs.Me.UsrDat.Prefs.Language]);
/***** Remove temporary file *****/
unlink (FileNameMail);
/***** Write message depending on return code *****/
return WEXITSTATUS (ReturnCode);
return ReturnCode;
}
/*****************************************************************************/