Refactored email service to use in-house RevDotNet solution. Added logging. Replaced sending of OI note on email send failure with mona critical status instead.

This commit is contained in:
Infineon\StieberD 2025-01-08 14:10:12 -07:00
parent dd178e1251
commit 0e51db912a
3 changed files with 105 additions and 55 deletions

View File

@ -0,0 +1,72 @@
Compile function Email_Services(@Service, @Params)
/***********************************************************************************************************************
This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
permission from Infineon Technologies.
Name : Email_Services
Description : Handler program for all module related services.
Notes : The generic parameters should contain all the necessary information to process the services. Often
this will be information like the data Record and Key ID.
Parameters :
Service [in] -- Name of the service being requested
Param1-10 [in/out] -- Additional request parameter holders
Response [out] -- Response to be sent back to the Controller (MCP) or requesting procedure
Metadata :
History : (Date, Initials, Notes)
01/08/25 djs Original programmer.
***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
$Insert APP_INSERTS
$Insert SERVICE_SETUP
$Insert REVDOTNETEQUATES
Declare subroutine Set_Property.Net, Error_Services
Declare function Environment_Services
GoToService
Return Response or ""
//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------
Service SendEmail(FromAddress, ToAddress, Subject, Body)
If ( (FromAddress NE '') and (ToAddress NE '') ) then
ErrorMessage = ''
EmailServer = Environment_Services('GetIfxEmailServer')
DotNetHandle = StartDotNet("","4.0")
DotNetDir = CheckDotNet('4.0'):'\'
MailDll = DotNetDir:'System.dll'
Set_Property.Net(DotNetHandle, "AssemblyName", MailDll)
If Not(Get_Status(ErrorMessage)) then
Params = FromAddress:@FM:ToAddress:@FM:Subject:@FM:Body
ParamTypes = 'System.String':@FM:'System.String':@FM:'System.String':@FM:'System.String'
objEmailMessage = Create_Class.Net(DotNetHandle, "System.Net.Mail.MailMessage", 0, Params, ParamTypes)
If Not(Get_Status(ErrorMessage)) then
objEmailClient = Create_Class.Net(DotNetHandle, "System.Net.Mail.SmtpClient", 0, EmailServer, 'System.String')
If Not(Get_Status(ErrorMessage)) then
rv = Send_Message.Net(objEmailClient, 'Send', objEmailMessage, 'RevDotNet', 0)
If Get_Status(ErrorMessage) then Null
Free_Class.Net(objEmailClient)
end
Free_Class.Net(objEmailMessage)
end
end
end else
ErrorMessage = 'Error in ':Service:' service. Null FromAddress or ToAddress passed into service.'
end
Response = (ErrorMessage EQ '')
If ErrorMessage NE '' then Error_Services('Add', ErrorMessage)
End Service

View File

@ -520,6 +520,13 @@ Service GetProveInApiUrl()
end service
Service GetIfxEmailServer()
Response = 'smtp.intra.infineon.com'
end service
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal GoSubs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -16,19 +16,27 @@ COMPILE FUNCTION obj_Notes(Method,Parms)
DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, NextKey, SRP_Send_Mail, obj_Calendar, Database_Services, SRP_Stopwatch
DECLARE SUBROUTINE Set_Status, Msg, obj_Tables, RList, ErrMsg, obj_Notes_Sent, Btree.Extract, Send_Info, obj_Notes
DECLARE SUBROUTINE Obj_Post_Log, SRP_Stopwatch, Notes_Services
DECLARE FUNCTION Email_Services, Environment_Services, Logging_Services
DECLARE SUBROUTINE Set_Status, Msg, obj_Tables, RList, ErrMsg, obj_Notes_Sent, Btree.Extract, Send_Info, obj_Notes
DECLARE SUBROUTINE Obj_Post_Log, SRP_Stopwatch, Notes_Services, Mona_Services, Logging_Services
$INSERT MSG_EQUATES
$INSERT NOTES_EQU
$INSERT NOTE_PTRS_EQU
$INSERT LSL_USERS_EQU
$INSERT EMAIL_BOX_EQUATES
$INSERT LOGICAL
$INSERT RLIST_EQUATES
$INSERT APP_INSERTS
$INSERT SRPMail_Inserts
EQU TARGET_ACTIVELIST$ TO 5
LogDate = Oconv(Date(), 'D4/')
LogTime = Oconv(Time(), 'MTS')
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\EmailService'
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' EmailService.csv'
Headers = 'Logging DTM' : @FM : 'Error'
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$)
ErrTitle = 'Error in Stored Procedure "obj_Notes"'
ErrorMsg = ''
@ -350,7 +358,6 @@ ForwardEMail:
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
ServiceKeyID = 'Obj_Notes*ForwardEMail'
Lock hSysLists, ServiceKeyID then
rv = Set_Status(0)
RList('SELECT EMAIL_BOX BY NOTE_KEY', 5, '', '', '')
Done = 0
@ -365,59 +372,22 @@ ForwardEMail:
eMailText = eMailBoxRec<EMAIL_BOX_EMAIL_TEXT$>
eMailHeader = eMailBoxRec<EMAIL_BOX_EMAIL_HEADER$>
OISentFrom = eMailBoxRec<EMAIL_BOX_FROM_USER$>
ConfigFile = ''
ConfigFile<1> = SendUsing_Port$
ConfigFile<2> = ''
ConfigFile<3> = 25 ;* Server port
ConfigFile<4> = 'smtp.intra.infineon.com' ;* Infinfeon Mail Server for internal recipents
ConfigFile<5> = Yes$ ;* Authenticate
ConfigFile<6> = 'oinotify@infineon.com' ;* Username (IFX)
ConfigFile<7> = 'oinotify1' ;* Password
ConfigFile<8> = No$ ;* Use SSL
SentFrom = 'oinotify@infineon.com'
SendTo = eMailAddr
SentFrom = 'oinotify@infineon.com'
SendTo = eMailAddr
IF OISentFrom = 'OI_ERROR' THEN SendTo := XLATE('SEC_GROUPS', 'OI_ADMIN', 'USER', 'X')
Message = ''
Message<1> = eMailHeader ; // Subject
Message<2> = SentFrom ; // From (email address)
Message<3> = SendTo ; // Send to (email address)
Message<5> = '' ; // Blind Carbon Copy (email address)
Message<6> = '' ; // Reply To (email address)
Message<7> = 'TEXT' ; // Content Type (TEXT or HTML)
Message<8> = eMailText ; // Content / Body
Message<9> = '' ; // Attachment(s) (path to file name(s))
MsgSent = SRP_Send_Mail(Message, ConfigFile)
IF MsgSent NE True$ THEN
Set_Status(0)
obj_Tables('UnlockRec',mbParms)
Recipients = XLATE('NOTIFICATION', 'FI_SUPPORT', 'USER_ID', 'X')
SentFrom = 'FI Support'
Subject = 'OpenInsight eMail Server Error'
Message = 'Unable to send email.' : \0D0A\
Message := 'Sent From: ' : SentFrom : \0D0A\
Message := 'Send To: ' : SendTo : \0D0A\
Message := 'Original Subject: ' : eMailHeader : \0D0A\
Message := 'Original Message: ' : eMailText : \0D0A\
Message := '========================================' : \0D0A\
Message := 'Error Message: ' : MsgSent
AttachWindow = ''
AttachKey = ''
SendToGroup = ''
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
END
Success = Email_Services('SendEmail', SentFrom, SendTo, eMailHeader, eMailText)
If Success then
Mona_Services('SendBufferedStatus', 'OPENINSIGHT_MES_OP_FE', 'Email-Service', 'ok')
end else
LogData = ''
LogData<1> = LoggingDtm
LogData<2> = Error_Services('GetMessage')
Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
Mona_Services('SendBufferedStatus', 'OPENINSIGHT_MES_OP_FE', 'Email-Service', 'critical')
end
obj_Tables('DeleteRec',mbParms)
end
REPEAT
Unlock hSysLists, ServiceKeyID else Null
end
@ -673,3 +643,4 @@ BulkCreate:
RETURN