#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, 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
}
New SMTP,MM,auth,blnClearUser
Set BodyIsStream=$G(BodyIsStream,0)
Set SMTP=##class(%Net.SMTP).%New()
Set SMTPServerNameOrIP=##class(TECH.Config.ConfigMgr).Instance().GetString("MiniMail_SMTPServerNameOrIP")
Set SMTP.smtpserver=SMTPServerNameOrIP
If $L($G(AuthUser)) Do
. Set auth=##class(%Net.Authenticator).%New() ; use default authentication list
. Set auth.UserName=AuthUser
. Set auth.Password=$G(AuthPwd)
. Set SMTP.authenticator=auth
. Set:($G(blnClearUser)) (AuthUser,AuthPwd)=""
Set MM=##class(%Net.MailMessage).%New()
Set MM.From=From
New Loop
For Loop=1:1:$LL(To) Do
. Do smmVoegToeRecipientsAanList(MM.To, $LI(To,Loop), ";")
If $D(ccTo) Do
. For Loop=1:1:$LL(ccTo) Do
. . Do smmVoegToeRecipientsAanList(MM.Cc, $LI(ccTo,Loop), ";")
If $D(BccTo) Do
. For Loop=1:1:$LL(BccTo) Do
. . 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) {
If $G(IsHTML) {
Set RecipientsInfo=$$$Replace(RecipientsInfo,$$$CRLF,"
")
Set RecipientsInfo=RecipientsInfo_"
"
}
Do MM.TextData.Write(RecipientsInfo)
Do MM.TextData.WriteLine()
}
If BodyIsStream Do
. Do MM.TextData.CopyFrom(Body)
Else Do
. Do MM.TextData.Write(Body)
Set:($D(IsHTML)) MM.IsHTML=IsHTML
;Attachments
New Status,Loop,Attachment,DirAndFileName,LastSlashPos,Dir,FileName,Binary
Set Status=$$$OK
For Loop=1:1:$LL(lbAttachments) Do Quit:($$$ISERR(Status))
. Set Attachment=$LI(lbAttachments,Loop)
. Set DirAndFileName=$LI(Attachment,1)
. Set Binary=$LG(Attachment,2,1) ; Default binary
. Set LastSlashPos=$L(DirAndFileName,"\")-1
. Set Dir=$P(DirAndFileName,"\",1,LastSlashPos)_"\"
. Set FileName=$P(DirAndFileName,"\",LastSlashPos+1)
. Set Status=MM.AttachFile(Dir,FileName,Binary)
Quit:($$$ISERR(Status)) Status
// 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 ##class(TECH.Mail.impl.MailMessageAanpasser).%New().MaakEmailAdressenAtVanhoeckeBe(MM)
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
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
Set RecipientsInfo=RecipientsInfo_"==========================================================="_$$$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)
#define MailsViaNotes01 1
Do:('$$$MailsViaNotes01) smxSenderFakeDomain(.From,lbTo,,)
Quit $$SendMiniMail(.From,.lbTo,.Subject,.Body,.BodyIsStream,.Args6,.Args7,.Args8,.lbAttachments,.Args10) ; ,.Args11,.Args12)
Quit ""
smxSenderFakeDomain(From,lbTo,DomainOrig,DomainRepl) ; From als .local doorgeven
// Replace the domain "vanhoecke.be" in if also contains "vanhoecke.be" domain(s)
#define VHDomainReal "vanhoecke.be"
#define VHDomainFake "vhmail.be"
Quit:($G(lbTo)="")
Set DomainOrig=$$smxAddAt($G(DomainOrig,$$$VHDomainReal))
Quit:($G(From)'[DomainOrig)
New i,blnReplace
Set blnReplace=0
For i=1:1:$LL(lbTo) Set:($LG(lbTo,i)[DomainOrig) blnReplace=1 Quit:(blnReplace)
If blnReplace Do
. Set DomainRepl=$$smxAddAt($G(DomainRepl,$$$VHDomainFake))
. Set From=$$$Replace(From,DomainOrig,DomainRepl)
Quit
smxAddAt(DomName)
Quit:($G(DomName)="") ""
Quit $S($E(DomName,1)="@":DomName, DomName["@":"@"_$P(DomName,"@",2), 1:"@"_DomName)
Quit DomName