Index: vhLib/Mail.mac.rou =================================================================== diff -u -r2 -r321 --- vhLib/Mail.mac.rou (.../Mail.mac.rou) (revision 2) +++ vhLib/Mail.mac.rou (.../Mail.mac.rou) (revision 321) @@ -1,16 +1,25 @@ #include vhLib.Macro + /// Forceer mail naar de orig. recipients, m.a.w. negeer de waarde van het ConfigItem "vhLib.Mail_RedirectMailToDevelopment" + /// Added by WimV on 12/10/2011 +SendMiniMailForced(From,To,Subject,Body,BodyIsStream,IsHTML,AuthUser,AuthPwd,lbAttachments,ReplyTo,ccTo,BccTo) + Quit $$SendMiniMail(From,To,Subject,.Body,.BodyIsStream,.IsHTML,.AuthUser,.AuthPwd,.lbAttachments,.ReplyTo,.ccTo,.BccTo, 1) + // ========================================================================================================================================== // Name : SendMiniMail // Author : Tom Rombaut // Function: Stuurt een minimail // ========================================================================================================================================== -SendMiniMail(From,To,Subject,Body,BodyIsStream,IsHTML,AuthUser,AuthPwd,lbAttachments,ReplyTo,ccTo,BccTo) +SendMiniMail(From,To,Subject,Body,BodyIsStream,IsHTML,AuthUser,AuthPwd,lbAttachments,ReplyTo,ccTo,BccTo, ForceToOrigRcpts) #Include %occOptions #Include %occStatus + // Default param value + Set ForceToOrigRcpts=$G(ForceToOrigRcpts,0) + Set lbAttachments=$get(lbAttachments) + If (##class(TECH.Config.ConfigMgr).Instance().GetBoolean("MiniMail_VoegServerPrefixToe")) { Set:($$$UCase(Subject)'[($$$Server)) Subject = "["_$$$Server_"]"_" "_Subject @@ -22,17 +31,6 @@ Set SMTPServerNameOrIP=##class(TECH.Config.ConfigMgr).Instance().GetString("MiniMail_SMTPServerNameOrIP") Set SMTP.smtpserver=SMTPServerNameOrIP - /* - If (##class(TECH.Config.ConfigMgr).Instance().GetBoolean("MiniMail_ ... ")) ; "..._UseSMTPServerAuthentication" - { - Set SMTP.smtpserver=SMTPServerNameOrIP ; "192.168.100.1" - If '$D(AuthUser) { ; Set default authentication - Set AuthUser="SMTPuser" - Set AuthPwd="���""&��" ; OPGELET: pwd bevat " ; uitgeschreven: ���"&�� (8 chars.) (==> 27031969) - Set blnClearUser=1 - } - } - */ If $L($G(AuthUser)) Do . Set auth=##class(%Net.Authenticator).%New() ; use default authentication list . Set auth.UserName=AuthUser @@ -43,15 +41,35 @@ Set MM.From=From New Loop For Loop=1:1:$LL(To) Do - . Do MM.To.Insert($LI(To,Loop)) + . Do smmVoegToeRecipientsAanList(MM.To, $LI(To,Loop), ";") If $D(ccTo) Do . For Loop=1:1:$LL(ccTo) Do - .. Do MM.Cc.Insert($LI(ccTo,Loop)) + . . Do smmVoegToeRecipientsAanList(MM.Cc, $LI(ccTo,Loop), ";") If $D(BccTo) Do . For Loop=1:1:$LL(BccTo) Do - .. Do MM.Bcc.Insert($LI(BccTo,Loop)) + . . Do smmVoegToeRecipientsAanList(MM.Bcc, $LI(BccTo,Loop), ";") + Set MM.ReplyTo=$G(ReplyTo) Set MM.Subject=Subject + + // Added by WimV on 11/10/2011 + New RecipientsInfo,RedirectTo + Set RecipientsInfo="" + If ($$$Not(ForceToOrigRcpts)) && (##class(TECH.Config.ConfigMgr).Instance().GetBoolean("vhLib.Mail_RedirectMailToDevelopment")) { + // Override mail recipients, stuur mail naar de actieve gebruiker (bedoeld voor test- en development-omgevingen) + Set RecipientsInfo=$$GeefRecipientsInfo(MM) + Set RedirectTo=$$GeefMailAdresFromRuntimeContext() + Set:(RedirectTo="") RedirectTo=##class(TECH.Config.ConfigMgr).Instance().GetString("TECH.Error.impl.ErrorHandler_DefaultMailAddress") + Do MM.To.Clear() + Do MM.Cc.Clear() + Do MM.Bcc.Clear() + Do MM.To.Insert(RedirectTo) + } + If $L(RecipientsInfo) { + Do MM.TextData.Write(RecipientsInfo) + Do MM.TextData.WriteLine() + } + If BodyIsStream Do . Do MM.TextData.CopyFrom(Body) Else Do @@ -71,12 +89,74 @@ Quit:($$$ISERR(Status)) Status + //Do MaakEmailAdressenAtVanhoeckeBe(MM) ; Added by WimV on 11/10/2011 + Set Status=SMTP.Send(MM) do MM.%Close() do SMTP.%Close() Quit Status +smmVoegToeRecipientsAanList(RecipientsList, ToeTeVoegenRecipients, Delimiter) + If $L(ToeTeVoegenRecipients,Delimiter)>1 { + Set Iterator = ##class(TECH.ListIterator).%New(##class(TECH.ListUtils).PiecesToList(ToeTeVoegenRecipients, Delimiter)) + While (Iterator.HasNext()) { + Do RecipientsList.Insert(Iterator.Next()) + } + } + Else { + Do RecipientsList.Insert(ToeTeVoegenRecipients) + } + Quit +MaakEmailAdressenAtVanhoeckeBe(MailMessage) + // De EmailAdressen controleren op aanwezigheid van het "@"-teken, en indien nodig aanvullen met "@vanhoecke.be" + // Bvb als alleen initialen zijn opgegeven, dit is geen geldig email-adres + Do MaakRecipientsAtVanhoeckeBe(MailMessage.To) + Do MaakRecipientsAtVanhoeckeBe(MailMessage.Cc) + Do MaakRecipientsAtVanhoeckeBe(MailMessage.Bcc) + Set MailMessage.From=$$GeefVolledigEmailAdres(MailMessage.From) + Set MailMessage.Sender=$$GeefVolledigEmailAdres(MailMessage.Sender) + Set MailMessage.ReplyTo=$$GeefVolledigEmailAdres(MailMessage.ReplyTo) + Quit + +MaakRecipientsAtVanhoeckeBe(ListOfRecipients) + New i,Recipient,IsEmailAdresGewijzigd + If $IsObject(ListOfRecipients) { + For i=1:1:ListOfRecipients.Count() { + Set Recipient=$$GeefVolledigEmailAdres(ListOfRecipients.GetAt(i), .IsEmailAdresGewijzigd) + Do:(IsEmailAdresGewijzigd) ListOfRecipients.SetAt(Recipient,i) + } + } + Quit + +GeefVolledigEmailAdres(EmailAdres, IsEmailAdresGewijzigd) ; IsEmailAdresGewijzigd als .local doorgeven + Set IsEmailAdresGewijzigd=0 + If ($L(EmailAdres))&&(EmailAdres'["@") { + Set EmailAdres=EmailAdres_"@vanhoecke.be" + Set IsEmailAdresGewijzigd=1 + } + Quit EmailAdres + + +GeefRecipientsInfo(MailMessage) + #define ListHasItems(%v) ($IsObject(%v))&&(%v.Count()>0) + New RecipientsInfo + Set RecipientsInfo="Intended Recipients : (redirected by configitem vhLib.Mail_RedirectMailToDevelopment)"_$$$CRLF + Set:($$$ListHasItems(MailMessage.To) ) RecipientsInfo=RecipientsInfo_" To : "_##class(TECH.ListUtils).ListToPieces(MailMessage.To,", ")_$$$CRLF + Set:($$$ListHasItems(MailMessage.Cc) ) RecipientsInfo=RecipientsInfo_" Cc : "_##class(TECH.ListUtils).ListToPieces(MailMessage.Cc,", ")_$$$CRLF + Set:($$$ListHasItems(MailMessage.Bcc)) RecipientsInfo=RecipientsInfo_" Bcc : "_##class(TECH.ListUtils).ListToPieces(MailMessage.Bcc,", ")_$$$CRLF + Quit RecipientsInfo + +GeefMailAdresFromRuntimeContext() + New RedirectTo + Set RedirectTo=##class(TECH.Context.RuntimeContext).Instance().GeefGebruikerInitialen() + If $E(RedirectTo,1,3)="SYS" { + Set RedirectTo="" + } + ;Set RedirectTo=$$GeefVolledigEmailAdres(RedirectTo) ; Wordt sowieso aangepast door method MaakEmailAdressenAtVanhoeckeBe() + Quit RedirectTo + + // SendMiniMail eXtended : // Replace the domain "vanhoecke.be" in if also contains "vanhoecke.be" domain(s) SendMiniMailXtd(From,lbTo,Subject,Body,BodyIsStream,Args6,Args7,Args8,lbAttachments,Args10) ; ,Args11,Args12) @@ -102,4 +182,6 @@ Quit:($G(DomName)="") "" Quit $S($E(DomName,1)="@":DomName, DomName["@":"@"_$P(DomName,"@",2), 1:"@"_DomName) Quit DomName - \ No newline at end of file + + + \ No newline at end of file