KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/efusion1/dwzMail/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/efusion1/dwzMail/AdvancedMail.asp
<%


function SendMail ()
	if UploadMailError <> "" then
		Parametri = split(RG_MailParameter,"@@@_@@@_@@@")
		valueToRedirectSend = Parametri(24)
		SendMail = ""
		exit function
	end if
	if isAdvMailInsert = "-1" then
		createPassword()
	end if
	Parametri = split(RG_MailParameter,"@@@_@@@_@@@")
	'Operating = Clng(Parametri(18))
	Risposta = ""
	Cong = ""
	TotalMail = 0
	NumMail = 0
	SendMailID = session.SessionID
	TimeStart = left(Time(),8)
	
	if FileMatch & "" <> "" and NoSendFileExceed = "1" then
		Risposta = "9999"
	else
		if isAdvMailInsert = "-1" then			
			insertFromSendMail()
		end if
		if isAdvMailUpdate = "-1" then
			updateFromSendMail()
		end if
		if isAdvMailDelete = "-1" then
			deleteFromSendMail()
		end if
		
		Mailer = clng(Parametri(0))
		MailPar_1 = getDynamicValue(trim(Parametri(1)))
		MailPar_2 = getDynamicValue(trim(Parametri(2)))
		MailPar_3 = getDynamicValue(trim(Parametri(3)))
		MailPar_4 = getDynamicValue(trim(Parametri(4)))
		MailPar_5 = getDynamicValue(trim(Parametri(5)))
		MailPar_6 = getDynamicValue(trim(Parametri(28)))		
		FromName = trim(Parametri(6))
		FromMail = trim(Parametri(7))
		ReplyName = trim(Parametri(8))
		ReplyMail = trim(Parametri(9))
		ToName = trim(Parametri(10))
		ToMail = trim(Parametri(11))
		Cc = trim(Parametri(12))
		Bcc = trim(Parametri(13))
		ReturnReceipt = trim(Parametri(14))
		MailFormat = trim(Parametri(15))
		bodyHTML = MailFormat
		Priority = trim(Parametri(16))
		MailObject = trim(Parametri(17))
		if sendAllFilesInFolder = "" then
			sendAllFilesInFolder = trim(Parametri(20))
		end if
		sendAllFilesType = clng(Parametri(21))
		SendUploadedFile = Parametri(22)
		if ubound(Parametri)>=23 then
			CharsetCode = Parametri(23)
		else
			CharsetCode = "us-ascii;20127"
		end if
		valueToRedirectSend = Parametri(24)
		'Non cancellare
		'impostati nella funzione
		'NoSendFileExceed = tmp(25)
		'TotalFileSize = tmp(26)
		'sendMethod = tmp(27)
		
		regTableName = Parametri(29)
		regSendMail = Parametri(30)
		regListField = Parametri(31)
		writeLog = Parametri(32)
		logFileType = Parametri(33)
		PathLog = Parametri(34)
		removeVbCrLf = Parametri(35)
		if Parametri(36)<>"" then
			NumberMail = getValue(getDynamicValue(Parametri(36)))
			if isnumeric(NumberMail) then
				NumberMail = clng(NumberMail)
			else
				NumberMail = -1
			end if
		else
			NumberMail = -1
		end if
						
		if trim(RG_BodyText) <> "" then
			Message = trim(replace(replace(replace(replace(replace(RG_BodyText,"@@_@@_@@",chr(34)),chr(34) & " & chr(37) & " & chr(34),"%"),"myCrLf",vbcrlf),"myTab",vbtab),"myErre",vbcr))
		elseif BodyFromFile <> "" then
			Message = getBodyFromFile()
		elseif BodyFromDynamicPage <> "" then
			Message = getBodyFromDynamicPage(BodyFromDynamicPage)
		else
			Message = ""
		end if

		if StrSQL <> "" then
			Set Conn = Server.CreateObject("AdoDb.Connection")
			Conn.Open RG_Connection
			err.clear
			on error resume next
			TotalMail = 0
			Rs.open StrSQL,Conn,1
			if err.number<>0 then
				on error goto 0
				Rs.open StrSQL,Conn
				while not Rs.eof
					TotalMail = TotalMail + 1
					Rs.MoveNext
				wend
				Rs.close
				Rs.open StrSQL,Conn
			else
				TotalMail = Rs.RecordCount
				if TotalMail<1 then
					TotalMail = 0
					while not Rs.eof
						TotalMail = TotalMail + 1
						Rs.MoveNext
					wend
					Rs.close
					Rs.open StrSQL,Conn
				end if
			end if
			on error goto 0
			sendCong = ""
			
			if NumberMail <> -1 then
				if TotalMail > NumberMail then
					TotalMail = NumberMail
				end if
			end if
			
			do while not RS.eof
				NumMail = NumMail + 1
				if ProgressMail<>"" then
					writeProgressInfo "0",NumMail,TotalMail,SendMailID,TimeStart,getValue(ToMail)
					dwz_pause(2)
				end if
				select case Mailer
				case 1:	Risp = ASPEmail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
				case 2:	Risp = CDONTS_Mailer (MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
				case 3:	Risp = CDO_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, MailPar_6, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
				case 4:	Risp = JMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
				case 5:	Risp = SASmtpMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
				case 6:	Risp = ASPMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
				case else: Risp = "Mailer not found"		
				end select
				if Risp = "0" then
					Risposta = Risposta & sendCong & getValue(ToMail) & "_" & "Send"
					StatusSendMail = "Send"
					if regSendMail <> "0" then
						advMailRegSendMail regTableName, regListField
					end if
				else
					Risposta = Risposta & sendCong & getValue(ToMail) & "_" & "Not Send - " & Risp
					StatusSendMail = "Not Send - " & Risp
				end if
				if WriteLog <> "0" then
					LogText = ""
					LogText = LogText & "Date: " & now & vbcrlf
					LogText = LogText & "IP: " & Request.ServerVariables("REMOTE_HOST") & vbcrlf
					LogText = LogText & "Mail From: " & getValue(FromMail) & vbcrlf
					LogText = LogText & "Mail To: " & getValue(ToMail) & vbcrlf
					LogText = LogText & "Mail Cc: " & getValue(Cc) & vbcrlf
					LogText = LogText & "Mail Bcc: " & getValue(Bcc) & vbcrlf
					LogText = LogText & "Mail Object: " & getValue(MailObject) & vbcrlf
					LogText = LogText & "Status: " & StatusSendMail & vbcrlf
					LogText = LogText & "===========================================" & vbcrlf
					advMailWriteLog WriteLog, LogFileType, PathLog, LogText
				end if
				sendCong = "|"
				if NumberMail <> -1 then
					if NumMail >= NumberMail then
						exit do
					end if
				end if
				if requestStopSend() then
					exit do
				end if				
				RS.MoveNext
			loop
			Rs.close
			Conn.close
			Set Conn = nothing
			writeProgressInfo "DONE",NumMail,TotalMail,SendMailID,TimeStart,""
		else
			select case Mailer
			case 1:	Risp = ASPEmail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
			case 2:	Risp = CDONTS_Mailer (MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
			case 3:	Risp = CDO_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, MailPar_6, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
			case 4:	Risp = JMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
			case 5:	Risp = SASmtpMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
			case 6:	Risp = ASPMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, getValue(FromName), getValue(FromMail), getValue(ReplyName), getValue(ReplyMail), getValue(ToName), getValue(ToMail), getValue(Cc), getValue(Bcc), getValue(ReturnReceipt), MailFormat, Priority, getValue(MailObject), ReplaceMsg(getMessageValue(Message,MailFormat,removeVbCrLf)), SendUploadedFile, CharsetCode)
			case else: Risp = "Mailer not found"		
			end select
			if Risp = "0" then
				Risposta = getValue(ToMail) & "_" & "Send"
				StatusSendMail = "Send"
			else
				Risposta = getValue(ToMail) & "_" & "Not Send - " & Risp
				StatusSendMail = "Not Send - " & Risp
			end if
			if WriteLog <> "0" then
				LogText = ""
				LogText = LogText & "Date: " & now & vbcrlf
				LogText = LogText & "IP: " & Request.ServerVariables("REMOTE_HOST") & vbcrlf
				LogText = LogText & "Mail From: " & getValue(FromMail) & vbcrlf
				LogText = LogText & "Mail To: " & getValue(ToMail) & vbcrlf
				LogText = LogText & "Mail Cc: " & getValue(Cc) & vbcrlf
				LogText = LogText & "Mail Bcc: " & getValue(Bcc) & vbcrlf
				LogText = LogText & "Mail Object: " & getValue(MailObject) & vbcrlf
				LogText = LogText & "Status: " & StatusSendMail & vbcrlf
				LogText = LogText & "===========================================" & vbcrlf
				advMailWriteLog WriteLog, LogFileType, PathLog, LogText
			end if
		end if
	end if

	if trim(Parametri(19)) = "1" and OnLoadStart="0" then
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x=1 to Clng(Form.Files.getFilesCount)
			FileToDelete = Form.Files.getFileNameById(x)
			if RG_FS.FileExists(RG_Path & FileToDelete) then
				 RG_FS.DeleteFile(RG_Path & FileToDelete)
			end if
		next
		set RG_FS = nothing
	end if
	
	
	SendMail = Risposta
	
end function
	
'======================================
' Sends an email with CDONTS 
function CDONTS_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, FromName, FromMail, ReplyName, ReplyMail, ToName, ToMail, CcList, BccList, ReturnReceipt, MailFormat, Priority, MailObject, Message, SendUploadedFile, CharsetCode)

	Dim objMail, Risp
	Set objMail = Server.CreateObject("CDONTS.NewMail") 
	
	CharsetValue = split(CharsetCode,";")
	objMail.Value("Charset") = CharsetValue(0)
	
	if ToName<>"" then
		objMail.To = ToName & " <" & ToMail & ">"
	else
		objMail.To = ToMail
	end if
	
	if FromName<>"" then
		objMail.From = FromName & " <" & FromMail & ">"
	else
		objMail.From = FromMail
	end if
	if ReplyMail<>"" then
		if ReplyName<>"" then
			objMail.Value("Reply-to") = ReplyName & " <" & ReplyMail & ">"
		else
			objMail.Value("Reply-to") = ReplyMail
		end if
	end if
	if ReturnReceipt <> "" then
		objMail.Value("Disposition-Notification-To") = ReturnReceipt
	end if
	if CcList<>"" then
		objMail.Cc = replace(CcList,",",";")
	end if
	if BCcList<>"" then
		objMail.BCc = replace(BCcList,",",";")
	end if
	if clng(MailFormat) = 1 then
		objMail.BodyFormat = 0
		objMail.MailFormat = 0
	else
		objMail.BodyFormat = 1
		objMail.MailFormat = 1
	end if
	
	select case clng(Priority)
	case 1: objMail.importance = 2
	case 2: objMail.importance = 1
	case 3: objMail.importance = 0
	end select
	
	objMail.Subject = MailObject
	objMail.Body = Message
	
	'Aggiungo i file Upload
	if SendUploadedFile = "-1" then
		on error resume next
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x=1 to Form.Files.getFilesCount
			FileToAttach = Form.Files.getFileNameById(x)
			if RG_FS.FileExists(RG_Path & FileToAttach) then
				 objMail.AttachFile RG_Path & FileToAttach, FileToAttach
			end if
		next
		set RG_FS = nothing
		on error goto 0
	end if
	
	'aggiungo i file
	if FilesList <> "" then
		ListFile = split(FilesList,"|")
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x = 0 to ubound(ListFile)
			if right(ListFile(x),7)="@_rec_@" then
				FileToAttach = getValue(ListFile(x))
			else
				FileToAttach = ListFile(x)
			end if
			if FileToAttach <> "" then
				if RG_FS.fileExists(server.MapPath(FileToAttach)) then
					objMail.AttachFile server.MapPath(FileToAttach), getFileName(FileToAttach)
				end if
			end if
		next
		set RG_FS = nothing
	end if
	
	'Allego tutti i files di una cartella
	if 	sendAllFilesInFolder <> "" then
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		select case sendAllFilesType
		case 1
			set Folder = RG_FS.getFolder(server.MapPath(sendAllFilesInFolder))
		case else
			set Folder = RG_FS.getFolder(sendAllFilesInFolder)
		end select
		for each File in Folder.files
			objMail.AttachFile File.Path, File.Name
		next
		set RG_FS = nothing
	end if
	
	'aggiungo le immagini
	if ImagesList <> "" then
		ListImage = split(ImagesList,"|")
		for x = 0 to ubound(ListImage)
			valori = split(ListImage(x),";")
			objMail.AttachUrl server.MapPath(valori(0)), valori(1)
		next
	end if
	
	on error resume next
	objMail.Send
	if err.number<>0 then
		Risp = err.number & "_" & err.description
	else
		Risp = 0
	end if
	on error goto 0
	Set objMail = Nothing
	
	CDONTS_Mailer = Risp
	
end function

'======================================
' Sends an email with Soft Artisans SASmtpMail 
function SASmtpMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, FromName, FromMail, ReplyName, ReplyMail, ToName, ToMail, CcList, BccList, ReturnReceipt, MailFormat, Priority, MailObject, Message, SendUploadedFile, CharsetCode)
	
	Dim objMail, Risp
	Set objMail = Server.CreateObject("SoftArtisans.SMTPMail")
	objMail.RemoteHost = MailPar_1
	if MailPar_2 <> "" then
		objMail.SMTPLog = MailPar_2
	end if
	if MailPar_4 <> "" then
		objMail.UserName = MailPar_4
	end if
	if MailPar_5 <> "" then
		objMail.Password = MailPar_5
	end if
	
	CharsetValue = split(CharsetCode,";")
	objMail.CodePage = CharsetValue(1)
	objMail.CustomCharSet = CharsetValue(0)
	
	if ToName<>"" then
		objMail.AddRecipient ToName, ToMail
	else
		objMail.AddRecipient ToMail, ToMail
	end if
	
	if FromName<>"" then
		objMail.FromName = FromName
	end if
	objMail.FromAddress = FromMail
	
	if ReplyMail<>"" then
		objMail.ReplyTo = ReplyMail
	end if
	
	if ReturnReceipt <> "" then
		objMail.ReturnReceipt = True
		objMail.ConfirmRead = true
	end if
	
	if CcList<>"" then
		CcList = replace(CcList,",",";")
		ListaCc = split(CcList,";")
		for J=0 to ubound(ListaCc)
			objMail.AddCC ListaCc(J), ListaCc(J)
		next
	end if
	
	if BCcList<>"" then
		BCcList = replace(BCcList,",",";")
		ListaBCc = split(BCcList,";")
		for J=0 to ubound(ListaBCc)
			objMail.AddBCC ListaBCc(J), ListaBCc(J)
		next
	end if

	if clng(MailFormat) = 1 then
		objMail.HtmlText = Message
		objMail.contenttype = "text/html"
	else
		objMail.BodyText = Message
		objMail.contenttype = "text/plain"
	end if
	
	objMail.Subject = MailObject
	
	select case clng(Priority)
	case 1: objMail.Priority  = 1
	case 2: objMail.Priority  = 3
	case 3: objMail.Priority  = 5
	end select
	
	'Aggiungo i file Upload
	if SendUploadedFile = "-1" then
		on error resume next
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x=1 to Form.Files.getFilesCount
			FileToAttach = Form.Files.getFileNameById(x)
			if RG_FS.FileExists(RG_Path & FileToAttach) then
				 objMail.AddAttachment  RG_Path & FileToAttach
			end if
		next
		set RG_FS = nothing
		on error goto 0
	end if
		
	'aggiungo i file
	if FilesList <> "" then
		ListFile = split(FilesList,"|")
		for x = 0 to ubound(ListFile)
			if getValue(ListFile(x))<>"" then
				objMail.AddAttachment server.MapPath(getValue(ListFile(x)))
			end if
		next
	end if
	
	'Allego tutti i files di una cartella
	if 	sendAllFilesInFolder <> "" then
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		select case sendAllFilesType
		case 1
			set Folder = RG_FS.getFolder(server.MapPath(sendAllFilesInFolder))
		case else
			set Folder = RG_FS.getFolder(sendAllFilesInFolder)
		end select
		for each File in Folder.files
			objMail.AddAttachment File.Path
		next
		set RG_FS = nothing
	end if
	
	objMail.IgnoreMalformedAddress = true
	
	if objMail.SendMail then
		Risp = 0
	else
		Risp = objMail.response
	end if
	Set objMail = Nothing
	
	SASmtpMail_Mailer = Risp

end function

'======================================
' Sends an email with ASPMail 
function ASPMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, FromName, FromMail, ReplyName, ReplyMail, ToName, ToMail, CcList, BccList, ReturnReceipt, MailFormat, Priority, MailObject, Message, SendUploadedFile, CharsetCode)
	
	Dim objMail, Risp
	Set objMail = Server.CreateObject("SMTPsvg.Mailer")
	objMail.RemoteHost = MailPar_1
	if MailPar_2 <> "" then
		objMail.SMTPLog = MailPar_2
	end if
	
	CharsetValue = split(CharsetCode,";")
	objMail.CustomCharSet = CharsetValue(0)
	objMail.AddExtraHeader("Charset: " & CharsetValue(0))
	
	if ToName<>"" then
		objMail.AddRecipient ToName, ToMail
	else
		objMail.AddRecipient ToMail, ToMail
	end if
	
	if FromName<>"" then
		objMail.FromName = FromName
	end if
	objMail.FromAddress = FromMail
	
	if ReplyMail<>"" then
		objMail.ReplyTo = ReplyMail
	end if
	
	if ReturnReceipt <> "" then
		objMail.ReturnReceipt = True
		objMail.ConfirmRead = true
	end if
	
	if CcList<>"" then
		CcList = replace(CcList,",",";")
		ListaCc = split(CcList,";")
		for J=0 to ubound(ListaCc)
			objMail.AddCC ListaCc(J), ListaCc(J)
		next
	end if
	
	if BCcList<>"" then
		BCcList = replace(BCcList,",",";")
		ListaBCc = split(BCcList,";")
		for J=0 to ubound(ListaBCc)
			objMail.AddBCC ListaBCc(J), ListaBCc(J)
		next
	end if
	
	if clng(MailFormat) = 1 then
		objMail.contenttype = "text/html"
	else
		objMail.contenttype = "text/plain"
	end if
	objMail.BodyText = Message
	objMail.Subject = MailObject
	
	select case clng(Priority)
	case 1: objMail.Priority  = 1
	case 2: objMail.Priority  = 3
	case 3: objMail.Priority  = 5
	end select
	objmail.IgnoreMalformedAddress = true

	'Aggiungo i file Upload
	if SendUploadedFile = "-1" then
		on error resume next
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x=1 to Form.Files.getFilesCount
			FileToAttach = Form.Files.getFileNameById(x)
			if RG_FS.FileExists(RG_Path & FileToAttach) then
				 objMail.AddAttachment  RG_Path & FileToAttach
			end if
		next
		set RG_FS = nothing
		on error goto 0
	end if
		
	'aggiungo i file
	if FilesList <> "" then
		ListFile = split(FilesList,"|")
		for x = 0 to ubound(ListFile)
			if getValue(ListFile(x))<>"" then
				objMail.AddAttachment server.MapPath(getValue(ListFile(x)))
			end if
		next
	end if
	
	'Allego tutti i files di una cartella
	if 	sendAllFilesInFolder <> "" then
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		select case sendAllFilesType
		case 1
			set Folder = RG_FS.getFolder(server.MapPath(sendAllFilesInFolder))
		case else
			set Folder = RG_FS.getFolder(sendAllFilesInFolder)
		end select
		for each File in Folder.files
			objMail.AddAttachment File.Path
		next
		set RG_FS = nothing
	end if

	if objMail.SendMail then
		Risp = 0
	else
		Risp = objMail.Response
	end if
	Set objMail = Nothing
	ASPMail_Mailer = Risp

end function

'======================================
' Sends an email with JMail 
function JMail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, FromName, FromMail, ReplyName, ReplyMail, ToName, ToMail, CcList, BccList, ReturnReceipt, MailFormat, Priority, MailObject, Message, SendUploadedFile, CharsetCode)
	
	Dim objMail, Risp
	Set objMail = Server.CreateObject("JMail.Message") 
	
	if trim(MailPar_3) <> "" then
		objMail.MailServerUserName = trim(MailPar_3)
	end if
	
	if trim(MailPar_4) <> "" then
		objMail.MailServerPassword = trim(MailPar_4)
	end if
	
	on error resume next
	objMail.NoAutoContentID = true
	on error goto 0
	
	CharsetValue = split(CharsetCode,";")
	objMail.Charset = CharsetValue(0)
	
	if ToName<>"" then
		objMail.AddRecipient ToMail, ToName 
	else
		objMail.AddRecipient ToMail
	end if
	
	if FromName<>"" then
		objMail.FromName = FromName 
	end if
	objMail.From  = FromMail
	
	if ReplyMail<>"" then
		objMail.ReplyTo = ReplyMail
	end if
	
	if ReturnReceipt <> "" then
		objMail.ReturnReceipt = true 
	end if

	if CcList<>"" then
		CcList = replace(CcList,",",";")
		ListaCc = split(CcList,";")
		for J=0 to ubound(ListaCc)
			objMail.AddRecipientCC ListaCc(J) 
		next
	end if
	
	if BCcList<>"" then
		BCcList = replace(BCcList,",",";")
		ListaBCc = split(BCcList,";")
		for J=0 to ubound(ListaBCc)
			objMail.AddRecipientBCC ListaBCc(J) 
		next
	end if
	
	'aggiungo le immagini
	if ImagesList <> "" then
		ListImage = split(ImagesList,"|")
		for x = 0 to ubound(ListImage)
			valori = split(ListImage(x),";")
			cid = objMail.AddAttachment(server.MapPath(valori(0)), true)
			Message = replace(Message,valori(1),cid,1,-1,vbtextcompare)
		next
	end if
	
	if clng(MailFormat) = 1 then
		objMail.HTMLBody = Message
	else
		objMail.Body = Message
	end if
	
	objMail.Subject = MailObject
	
	select case clng(Priority)
	case 1: objMail.Priority  = 1
	case 2: objMail.Priority  = 3
	case 3: objMail.Priority  = 4
	end select
	
	'Aggiungo i file Upload
	if SendUploadedFile = "-1" then
		on error resume next
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x=1 to Form.Files.getFilesCount
			FileToAttach = Form.Files.getFileNameById(x)
			if RG_FS.FileExists(RG_Path & FileToAttach) then
				 objMail.AddAttachment  RG_Path & FileToAttach, false
			end if
		next
		set RG_FS = nothing
		on error goto 0
	end if
		
	'aggiungo i file
	if FilesList <> "" then
		ListFile = split(FilesList,"|")
		for x = 0 to ubound(ListFile)
			if getValue(ListFile(x)) then
				objMail.AddAttachment server.MapPath(getValue(ListFile(x))), false
			end if
		next
	end if
	
	'Allego tutti i files di una cartella
	if 	sendAllFilesInFolder <> "" then
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		select case sendAllFilesType
		case 1
			set Folder = RG_FS.getFolder(server.MapPath(sendAllFilesInFolder))
		case else
			set Folder = RG_FS.getFolder(sendAllFilesInFolder)
		end select
		for each File in Folder.files
			objMail.AddAttachment File.Path, false
		next
		set RG_FS = nothing
	end if
	
	objMail.silent = true
	
	if objMail.send(MailPar_1) then
		Risp = 0
	else
		Risp = objMail.ErrorMessage
	end if
	Set objMail = Nothing
	
	JMail_Mailer = Risp

end function

'======================================
' Sends an email with Persits ASPEmail 
function ASPEmail_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, FromName, FromMail, ReplyName, ReplyMail, ToName, ToMail, CcList, BccList, ReturnReceipt, MailFormat, Priority, MailObject, Message, SendUploadedFile, CharsetCode)

	Dim objMail, Risp
	Set objMail = Server.CreateObject("Persits.MailSender") 
	objMail.Host = MailPar_1
	if MailPar_2 <> "" then
		objMail.Port = MailPar_2
	end if
	if MailPar_4<>"" then
		objMail.Username = MailPar_4
	end if
	if MailPar_5<>"" then
		objMail.Password = MailPar_5
	end if
	
	CharsetValue = split(CharsetCode,";")
	objMail.Charset = CharsetValue(0)
	
	if ToName<>"" then
		objMail.AddAddress ToMail, ToName 
	else
		objMail.AddAddress ToMail
	end if
	
	if FromName<>"" then
		objMail.FromName = FromName 
	end if
	objMail.From  = FromMail
	
	if ReplyMail<>"" then
		objMail.AddReplyTo ReplyMail
	end if
	
	if ReturnReceipt <> "" then
		objMail.AddCustomHeader "Return-Receipt-To: <" & ReturnReceipt & ">" 
	end if
	
	if CcList<>"" then
		CcList = replace(CcList,",",";")
		ListaCc = split(CcList,";")
		for J=0 to ubound(ListaCc)
			objMail.AddCC ListaCc(J)
		next
	end if
	
	if BCcList<>"" then
		BCcList = replace(BCcList,",",";")
		ListaBCc = split(BCcList,";")
		for J=0 to ubound(ListaBCc)
			objMail.AddBcc ListaBCc(J)
		next
	end if
	
	if clng(MailFormat) = 1 then
		objMail.IsHTML = true
	else
		objMail.IsHTML = false
	end if
	
	err.clear
	on error resume next
	objMail.Body = objMail.EncodeHeader( Message, CharsetValue = CharsetValue(2) & "," & CharsetValue(0) & "," & CharsetValue(1))
	objMail.Subject = objMail.EncodeHeader( MailObject, CharsetValue = CharsetValue(2) & "," & CharsetValue(0) & "," & CharsetValue(1))
	if err.number <> 0 then
		objMail.Body = Message
		objMail.Subject = MailObject
	end if
	on error goto 0
	
	select case clng(Priority)
	case 1: objMail.Priority  = 1
	case 2: objMail.Priority  = 3

	case 3: objMail.Priority  = 5
	end select
	
	'Aggiungo i file Upload
	if SendUploadedFile = "-1" then
		on error resume next
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x=1 to Form.Files.getFilesCount
			FileToAttach = Form.Files.getFileNameById(x)
			if RG_FS.FileExists(RG_Path & FileToAttach) then
				 objMail.AddAttachment RG_Path & FileToAttach
			end if
		next
		set RG_FS = nothing
		on error goto 0
	end if
		
	'aggiungo i file
	if FilesList <> "" then
		ListFile = split(FilesList,"|")
		for x = 0 to ubound(ListFile)
			if getValue(ListFile(x)) then
				objMail.AddAttachment server.MapPath(getValue(ListFile(x)))
			end if
		next
	end if
	
	'Allego tutti i files di una cartella
	if 	sendAllFilesInFolder <> "" then
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		select case sendAllFilesType
		case 1
			set Folder = RG_FS.getFolder(server.MapPath(sendAllFilesInFolder))
		case else
			set Folder = RG_FS.getFolder(sendAllFilesInFolder)
		end select
		for each File in Folder.files
			objMail.AddAttachment File.Path
		next
		set RG_FS = nothing
	end if
	
	'aggiungo le immagini
	if ImagesList <> "" then
		ListImage = split(ImagesList,"|")
		for x = 0 to ubound(ListImage)
			valori = split(ListImage(x),";")
			objMail.AddEmbeddedImage server.MapPath(valori(0)), valori(1)
		next
	end if
	
	On Error Resume Next
	objMail.Send
	If Err <> 0 Then
	  Risp = Err.Description
	else
		Risp = 0
	end if
	Set objMail = Nothing
	On error goto 0
	
	ASPEmail_Mailer = Risp
	
end function

'======================================
' Sends an email with CDOSYS
function CDO_Mailer(MailPar_1, MailPar_2, MailPar_3, MailPar_4, MailPar_5, MailPar_6, FromName, FromMail, ReplyName, ReplyMail, ToName, ToMail, CcList, BccList, ReturnReceipt, MailFormat, Priority, MailObject, Message, SendUploadedFile, CharsetCode)

	Dim objMail, Risp
	Set objMail = Server.CreateObject("CDO.Message") 
	
	if (MailPar_1<>"")  then
		objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailPar_1
		
		if MailPar_6<>"0" and trim(MailPar_6)<>"" then
			objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = clng(MailPar_6)
		else
			objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
		end if	
		if (isNumeric(MailPar_2))  then
			objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = cInt(MailPar_2)
		end if
		if isNumeric(MailPar_3) then
			objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cInt(MailPar_3)
		end if
		if (MailPar_4 <> "")  then
			objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = MailPar_4
		end if 
		if (MailPar_5 <> "")  then
			objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = MailPar_5
		end if
		if MailPar_4 <> "" or MailPar_5 <> ""  then
			objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
		end if
		objMail.Configuration.Fields.Update	
	end if
	
	CharsetValue = split(CharsetCode,";")
	objMail.BodyPart.Charset = CharsetValue(0)
	
	if ToName<>"" then
		objMail.To = ToName & " <" & ToMail & ">"
	else
		objMail.To = ToMail
	end if
	
	if FromName<>"" then
		objMail.From = FromName & " <" & FromMail & ">"
	else
		objMail.From = FromMail
	end if
	if ReplyMail<>"" then
		if ReplyName<>"" then
			objMail.ReplyTo = ReplyName & " <" & ReplyMail & ">"
		else
			objMail.ReplyTo = ReplyMail
		end if
	end if
	
	if ReturnReceipt <> "" then
		objMail.mdnrequested  = true
   		objMail.Configuration.fields("http://schemas.microsoft.com/cdo/configuration/cdoDispositionNotificationTo") = ReturnReceipt
   		objMail.Configuration.fields.update
	end if
	
	if CcList<>"" then
		objMail.Cc = replace(CcList,";",",")
	end if
	if BCcList<>"" then
		objMail.BCc = replace(BCcList,";",",")
	end if

	Set iBp = objMail.BodyPart
	Set iBp2 = iBp.AddBodyPart
	
	if clng(MailFormat) = 1 then
		Set iBp3 = iBp2.AddBodyPart
		With iBp3
		   .ContentMediaType        = "text/html"
		   .ContentTransferEncoding = "quoted-printable"
		   .Charset = CharsetValue(0)
		   Set Stm = .GetDecodedContentStream
		   Stm.WriteText Message
		   Stm.Flush
		End With
	else
		Set iBp3 = iBp2.AddBodyPart
		With iBp3
		   .ContentMediaType        = "text/plain"
		   .ContentTransferEncoding = "7bit"
		   .Charset = CharsetValue(0)
		   Set Stm = .GetDecodedContentStream
		   Stm.WriteText Message
		   Stm.Flush
		End With
	end if
		
	select case clng(Priority)
	case 1
		objMail.Configuration.Fields("http://schemas.microsoft.com/exchange/events/Priority") = 1
  		objMail.Configuration.Fields.Update
	case 2
		objMail.Configuration.Fields("http://schemas.microsoft.com/exchange/events/Priority") = 3
  		objMail.Configuration.Fields.Update
	case 3
		objMail.Configuration.Fields("http://schemas.microsoft.com/exchange/events/Priority") = 5
  		objMail.Configuration.Fields.Update
	end select
	
	objMail.Subject = MailObject
	
	'aggiungo le immagini
	if ImagesList <> "" then
		iBp.ContentMediaType = "multipart/related"
		iBp2.ContentMediaType = "multipart/alternative"
		ListImage = split(ImagesList,"|")
		for x = 0 to ubound(ListImage)
			valori = split(ListImage(x),";")
			Set iBp2 = iBp.AddBodyPart
			With iBp2
			   .ContentMediaType = "image/gif"
			   .ContentTransferEncoding = "base64"
			   Set Flds = iBp2.Fields
			   Flds("urn:schemas:mailheader:content-disposition") = "attachment" 
			   Flds("urn:schemas:mailheader:content-location") = valori(1)
			   Flds.Update
			   Set Stm = .GetDecodedContentStream
			   Stm.LoadFromFile server.MapPath(valori(0))
			   Stm.Flush
			End With
		next
	end if

	'Aggiungo i file Upload
	if SendUploadedFile = "-1" then
		on error resume next
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x=1 to Form.Files.getFilesCount
			FileToAttach = Form.Files.getFileNameById(x)
			if RG_FS.FileExists(RG_Path & FileToAttach) then
				 objMail.AddAttachment RG_Path & FileToAttach
			end if
		next
		set RG_FS = nothing
		on error goto 0
	end if
		
	'aggiungo i file
	if FilesList <> "" then
		on error resume next
		ListFile = split(FilesList,"|")
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		for x = 0 to ubound(ListFile)
			if getValue(ListFile(x))<>"" then
				if RG_FS.FileExists(server.MapPath(getValue(ListFile(x)))) then
					objMail.AddAttachment server.MapPath(getValue(ListFile(x)))
				end if
			end if
		next
		set RG_FS = nothing
		on error goto 0
	end if
		
	
	'Allego tutti i files di una cartella
	if 	sendAllFilesInFolder <> "" then
		set RG_FS = server.createObject( "Scripting.FileSystemObject")
		select case sendAllFilesType
		case 1
			set Folder = RG_FS.getFolder(server.MapPath(sendAllFilesInFolder))
		case else
			set Folder = RG_FS.getFolder(sendAllFilesInFolder)
		end select
		for each File in Folder.files
			objMail.AddAttachment File.Path
		next
		set RG_FS = nothing
	end if
	
	on error resume next
	objMail.Send

	if err.number<>0 then
		Risp = err.number & "_" & err.description
	else
		Risp = 0
	end if
	on error goto 0
	Set objMail = Nothing
	
	CDO_Mailer = Risp
	
end function

function getValue(Str)
	getValueStr = Str
	if Str <> "" then
	'"Form variable","Session","Application","Cookie","Entered value","Eval function"
	'"@_rec_@","@_UrlPar_@","@_form_@","@_Session_@","@_Appl_@","@_Cookie_@","@_value_@","@_eval_@"
		if instrRev(Str,"@_") > 0 then
			valueFrom = mid(Str, instrRev(Str,"@_"))
		else
			valueFrom = ""
		end if
		select case valueFrom
		case "@_rec_@"
			RecValue = ""
			on error resume next
			RecValue = trim(RS(replace(trim(Str),"@_rec_@","",1,-1,vbtextcompare)))
			on error goto 0
			getValueStr = RecValue
		case "@_form_@"
			getValueStr = trim(UploadFormRequest(replace(trim(Str),"@_form_@","",1,-1,vbtextcompare)))
		case "@_UrlPar_@"
			getValueStr = trim(request.QueryString(replace(trim(Str),"@_UrlPar_@","",1,-1,vbtextcompare)))
		case "@_Session_@"
			getValueStr = trim(Session(replace(trim(Str),"@_Session_@","",1,-1,vbtextcompare)))
		case "@_Appl_@"
			getValueStr = trim(Application(replace(trim(Str),"@_Appl_@","",1,-1,vbtextcompare)))
		case "@_Cookie_@"
			CookieValue = ""
			on error resume next
			CookieValue = trim(request.Cookies(replace(trim(Str),"@_Cookie_@","",1,-1,vbtextcompare)))
			on error goto 0
			getValueStr = CookieValue
		case "@_value_@"
			getValueStr = replace(Str,"@_value_@","",1,-1,vbtextcompare)
		case "@_eval_@"
			getValueStr = eval(replace(Str,"@_eval_@","",1,-1,vbtextcompare))
		case else
			getValueStr = getDynamicValue(Str)
		end select
	end if
	getValue = getValueStr
end function

function getMessageValue(Str_1,FormatoMail, sReplace)
	Str_1 = getDynamicValue(Str_1)
	if clng(FormatoMail) = 1 and (instr(Str_1,"@_form_@") > 0 or instr(Str_1,"@_rec_@") > 0) then
		retStr = replace(getValue(Str_1),"#_Dwz_Password_#",newPassword,1,-1,vbtextcompare)
	else
		retStr = replace(getValue(Str_1),"#_Dwz_Password_#",newPassword,1,-1,vbtextcompare)
	end if
	if sReplace <> "0" then
		retStr = replace(retStr, vbcrlf, "<br>")
	end if
	getMessageValue = retStr
end function

function getDynamicValue(str)
	valore = str
	if trim(Valore)<>"" then
		valore = replace(valore,"@_''_@",chr(34))
		while instr(valore,"@_start_@")>0
			inizio = instr(valore,"@_start_@") + 9
			fine = instr(inizio,valore,"@_end_@")
			lung = fine-inizio
			valore = left(valore,inizio-10) & eval(mid(valore,inizio,lung)) & mid(valore,fine + 7)
		wend
	end if
	getDynamicValue = valore	
end function

function ReplaceMsg(Str)
	ReplaceMsgStr = Str
	if ReplaceList <> "" then
		ListToReplace = split(ReplaceList,"|")
		for x = 0 to ubound(ListToReplace)
			valori = split(ListToReplace(x),";")
			ReplaceMsgStr = replace(ReplaceMsgStr,valori(0),getValue(valori(1)) & "",1,-1,vbtextcompare)
		next
	end if
	ReplaceMsg = ReplaceMsgStr	
end function

sub setParamVal()
	Set ParamVal = CreateObject("Scripting.Dictionary")
	tmp = split(RG_Files,"@_@_@")
	ParamList = split(tmp(0),"|")
	MaxFieldNumber = ubound(ParamList)
	for x=0 to Ubound(ParamList)
		TmpVal = Split(ParamList(x),";")
		for y=0 to ubound(TmpVal)
			Key = right("00" & cstr(x),3) & cstr(y)
			ParamVal.add Key, TmpVal(y)
		next
	next
end sub

function getBodyFromFile()
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	if objFSO.FileExists(server.MapPath(BodyFromFile)) then
		Set Contenuto = objFSO.OpenTextFile(server.MapPath(BodyFromFile), 1)
		getBodyFromFile = Contenuto.ReadAll
		Contenuto.close
	else
		getBodyFromFile = ""
	end if
	set objFSO = Nothing
end function

function getRedirectForMail(MailError)
	
	if instr(1,editRedirectUrl,".html",vbtextcompare)>0 or instr(1,editRedirectUrl,".htm",vbtextcompare)>0 then
		newPage = "<script language=javascript>location='" & editRedirectUrl & "'</script>"
	else
		if Request.QueryString<>"" then
			newQryString = ""
			cong = ""
			For Each item In Request.QueryString
				if lcase(item)<>"uploadid" then
					newQryString = cong & item &  "=" & Request.QueryString(item)
					cong = "&"
				end if
			Next
						
			if newQryString<>"" then
				if instr(1,editRedirectUrl,"?",vbtextcompare)>0 then
					separ = "&"
				else
					separ = "?"
				end if
			end if
			editRedirectUrl = editRedirectUrl & separ & newQryString
		end if
		
		tmpPar = split(RG_MailParameter,"@@@_@@@_@@@")
		
		newPage = "<html><head>"
		newPage = newPage & "</head><body >"
		
		newPage = newPage & "<form action=" & chr(34) & editRedirectUrl & chr(34) & " method=" & chr(34) & tmpPar(27) & chr(34) & " name=" & chr(34) & "myForm" & chr(34) & " Id=" & chr(34) & "myForm" & chr(34) & ">"
		
		if valueToRedirectSend <> "" then
			listToSend = split(valueToRedirectSend,"|")
			for x = 0 to ubound(listToSend)
				newPage = newPage & "<input name=" & chr(34) & listToSend(x) & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & UploadFormRequest(listToSend(x)) & chr(34) & ">"
			next
		end if
			
		if UploadMailError = "" then
			newPage = newPage & UploadStatus
			newPage = newPage & "<input name=" & chr(34) & "NumFile" & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & NumFile & chr(34) & ">"
		else
			newPage = newPage & "<input name=" & chr(34) & "UploadedSize" & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & UploadMailError & chr(34) & ">"
			newPage = newPage & "<input name=" & chr(34) & "MaxFileSize" & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & TotalFileSize & chr(34) & ">"
		end if
		
		if not isnull(MailError) and MailError<>"" then
			newPage = newPage & "<input name=" & chr(34) & "MailReport" & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & replace(MailError,chr(34),"") & chr(34) & ">"
		end if
		
		newPage = newPage & "</form>"
		newPage = newPage & "<script language=" & chr(34) & "JavaScript" & chr(34) & ">document.getElementById('myForm').submit();</script>"
		newPage = newPage & "</body></html>"
	end if
	
	getRedirectForMail = newPage
end function

sub deleteProgressMail(S_ID)
	Set FS = CreateObject("Scripting.FileSystemObject")
	err.clear
	on error resume next
	TempFileName = getTempFolder() & "\ms" & S_ID & ".~tmp"	
	if Fs.FileExists(TempFileName) then
		Fs.DeleteFile(TempFileName)
	end if
	set myFolder = Fs.getFolder(getTempFolder())
	for each File in myFolder.files
		if left(lcase(File.name),2)="ms" or left(lcase(File.name),2)="pu" then
			if cdate(File.DateCreated) < dateAdd("d",-1,now()) then
				Fs.DeleteFile File.path
			end if
		end if
	next
	if err.number<>0 then
		response.Clear()
		response.write("WARNING!!<br>")
		response.write("The Advanced Mail behavior use a temp folder to save same info<br>")
		response.write("The default temp folder is the System temp folder (" & getTempFolder() & ")<br>")
		response.write("but in this folder you don't have the write permission<br>")
		response.write("You have 2 solutions:<br>")
		response.write("1) Give the write permission to the system temp folder<br>")
		response.write("2) Change the temp folder for this behavior<br>")
		response.write("To change the temp folder read this tutorial:<br>")
		response.write("<a href='http://www.DwZone-it.com/Extension/AdvMail/Help.asp'>Download tutorial</a><br>")
		response.end
	end if
	on error goto 0
	set FS = nothing	
end sub


sub writeProgressInfo(Stato,N_Mail,T_Mail,S_ID,StartTime,MailAccount)
	Application.Lock()
	Set FS = CreateObject("Scripting.FileSystemObject")
	'TempFolder = FS.GetSpecialFolder(2)
	TempFileName = getTempFolder() & "\ms" & S_ID & ".~tmp"
	LineaFile = Stato & "," & N_Mail & "," & T_Mail & "," & StartTime & "," & left(Time(),8) & "," & MailAccount
	on error resume next
	set tmpFile = FS.OpenTextFile(TempFileName, 2, true)
	tmpFile.WriteLine (LineaFile)
	tmpFile.close
	on error goto 0
	set FS = nothing
	Application.UnLock()
end sub

function getBodyFromDynamicPage(page)
	
	set objXMLHTTP = Server.CreateObject(getXmlObject())
	if left(lcase(page),7) = "http://" then
		url = page
	else
		if left(page,1)<>"/" then
			page = "/" & page
		end if
		url = "http://" & Request.ServerVariables("HTTP_HOST") & page
	end if
	objXMLHTTP.open "get", url, false
	objXMLHTTP.Send
	resultCode = objXMLHTTP.responseText
	set objXMLHTTP = nothing
	
	getBodyFromDynamicPage = resultCode
end function

function insertFromSendMail()
	
	RG_fields = Split(getAdvMailPlugInParameter("AdvMail_fieldsStr"), "|")
	RG_columns = Split(getAdvMailPlugInParameter("AdvMail_columnsStr"), "|")
	
	For RG_i = LBound(RG_fields) To UBound(RG_fields) Step 2
		RG_fields(RG_i+1) = CStr(UploadFormRequest(RG_fields(RG_i)))
	Next
	
	RG_tableValues = ""
	RG_dbValues = ""
	For RG_i = LBound(RG_fields) To UBound(RG_fields) Step 2
		RG_formVal = RG_fields(RG_i+1)
		RG_typeArray = Split(RG_columns(RG_i+1),",")
		RG_delim = RG_typeArray(0)
		If (RG_delim = "none") Then RG_delim = ""
		RG_altVal = RG_typeArray(1)
		If (RG_altVal = "none") Then RG_altVal = ""
		RG_emptyVal = RG_typeArray(2)
		If (RG_emptyVal = "none") Then RG_emptyVal = ""
		If (RG_formVal = "") Then
			RG_formVal = RG_emptyVal
		Else
		  If (RG_altVal <> "") Then
			RG_formVal = RG_altVal
		  ElseIf (RG_delim = "'") Then  
			RG_formVal = "'" & Replace(RG_formVal,"'","''") & "'"
		  Elseif (RG_delim = "d") Then
			RG_formVal = FormatDateForMySql(RG_formVal)
		  Else
			RG_formVal = RG_delim + RG_formVal + RG_delim
		  End If
		End If
		If (RG_i <> LBound(RG_fields)) Then
		  RG_tableValues = RG_tableValues & ","
		  RG_dbValues = RG_dbValues & ","
		End If
		RG_tableValues = RG_tableValues & verFieldTableName(RG_columns(RG_i))
		RG_dbValues = RG_dbValues & RG_formVal
	Next
	
	if getAdvMailPlugInParameter("AdvMail_PwdField") <> "" and newPassword <> "" then
		if RG_tableValues <> "" then
			RG_tableValues = RG_tableValues & ","
			RG_dbValues = RG_dbValues & ","
		end if
		RG_tableValues = RG_tableValues & verFieldTableName(getAdvMailPlugInParameter("AdvMail_PwdField"))
		RG_dbValues = RG_dbValues & "'" & newPassword & "'"
	end if
	
	Set Conn = Server.CreateObject("AdoDb.Connection")
	Conn.Open getAdvMailPlugInParameter("AdvMail_editConnection")
	
	if isSingleMailRecord() then
		RG_tableValuesTmp = ""
		RG_dbValuesTmp = ""
		cong = ","
		for J=1 to QtyRecord
			if tmpField_Name(J)<>"" then
				RG_tableValuesTmp = RG_tableValuesTmp & cong & tmpField_Name(J)
				RG_dbValuesTmp = RG_dbValuesTmp & cong & tmpValue_Name(J)
			end if
			if tmpField_Size(J)<>"" then
				RG_tableValuesTmp = RG_tableValuesTmp & cong & tmpField_Size(J)
				RG_dbValuesTmp = RG_dbValuesTmp & cong & tmpValue_Size(J)
			end if
		next
		RG_editQuery = "insert into " & verFieldTableName(getAdvMailPlugInParameter("AdvMail_editTable")) & " (" & RG_tableValues & RG_tableValuesTmp & ") values (" & RG_dbValues & RG_dbValuesTmp & ")"
		on error resume next
		Conn.execute (RG_editQuery)
		if err.number<>0 then
			FirstError = err.Description
			err.clear
			RG_editQuery = replace(replace(RG_editQuery,"[",""),"]","")
			Conn.execute (RG_editQuery)
			if err.number<>0 then
				err.clear
				RG_editQuery = replace(replace(RG_editQuery,"[","`"),"]","`")
				Conn.execute (RG_editQuery)
				if err.number<>0 then
					response.write "I find an error in the sql:<br>" & replace(replace(RG_editQuery,"`",""),"`","")  & "<br>" & "I find this error: " & FirstError
					response.end
				end if
			end if
		end if
		on error goto 0
	else
		for J=1 to QtyRecord
			RG_tableValuesTmp = ""
			RG_dbValuesTmp = ""
			cong = ","
			if tmpField_Name(J)<>"" then
				RG_tableValuesTmp = RG_tableValuesTmp & cong & tmpField_Name(J)
				RG_dbValuesTmp = RG_dbValuesTmp & cong & tmpValue_Name(J)
			end if
			if tmpField_Size(J)<>"" then
				RG_tableValuesTmp = RG_tableValuesTmp & cong & tmpField_Size(J)
				RG_dbValuesTmp = RG_dbValuesTmp & cong & tmpValue_Size(J)
			end if
			RG_editQuery = "insert into " & verFieldTableName(getAdvMailPlugInParameter("AdvMail_editTable")) & " (" & RG_tableValues & RG_tableValuesTmp & ") values (" & RG_dbValues & RG_dbValuesTmp & ")"
			on error resume next
			Conn.execute (RG_editQuery)
			if err.number<>0 then
				FirstError = err.Description
				err.clear
				RG_editQuery = replace(replace(RG_editQuery,"[",""),"]","")
				Conn.execute (RG_editQuery)
				if err.number<>0 then
					err.clear
					RG_editQuery = replace(replace(RG_editQuery,"[","`"),"]","`")
					Conn.execute (RG_editQuery)
					if err.number<>0 then
						response.write "I find an error in the sql:<br>" & replace(replace(RG_editQuery,"`",""),"`","") & "<br>" & "I find this error: " & FirstError
						response.end
					end if
				end if
			end if
			on error goto 0
		next
	end if
	Conn.close
	Set Conn = nothing	
		
end function





function updateFromSendMail
		
	RG_fields = Split(getAdvMailPlugInParameter("AdvMail_fieldsStr"), "|")
	RG_columns = Split(getAdvMailPlugInParameter("AdvMail_columnsStr"), "|")

	For RG_i = LBound(RG_fields) To UBound(RG_fields) Step 2
		RG_fields(RG_i+1) = CStr(UploadFormRequest(RG_fields(RG_i)))
	Next
	
	RG_editQuery = "update " & verFieldTableName(getAdvMailPlugInParameter("AdvMail_editTable")) & " set "
	For RG_i = LBound(RG_fields) To UBound(RG_fields) Step 2
		RG_formVal = RG_fields(RG_i+1)
		RG_typeArray = Split(RG_columns(RG_i+1),",")
		RG_delim = RG_typeArray(0)
		If (RG_delim = "none") Then RG_delim = ""
		RG_altVal = RG_typeArray(1)
		If (RG_altVal = "none") Then RG_altVal = ""
		RG_emptyVal = RG_typeArray(2)
		If (RG_emptyVal = "none") Then RG_emptyVal = ""
		If (RG_formVal = "") Then
		  RG_formVal = RG_emptyVal
		Else
		  If (RG_altVal <> "") Then
			RG_formVal = RG_altVal
		  ElseIf (RG_delim = "'") Then
			RG_formVal = "'" & Replace(RG_formVal,"'","''") & "'"
		  Elseif (RG_delim = "d") Then
		    RG_formVal = FormatDateForMySql(RG_formVal)
		  Else
			RG_formVal = RG_delim + RG_formVal + RG_delim
		  End If
		End If
		If (RG_i <> LBound(RG_fields)) Then
		  RG_editQuery = RG_editQuery & ","
		End If
		RG_editQuery = RG_editQuery & verFieldTableName(RG_columns(RG_i)) & " = " & RG_formVal
	Next
	
	if RG_editQueryTmp<>"" then
		RG_editQueryTmp = ", " & RG_editQueryTmp
	end if
	
	RG_editQuery = RG_editQuery & RG_editQueryTmp & " where " & verFieldTableName(getAdvMailPlugInParameter("AdvMail_editColumn")) & " = " & getAdvMailPlugInParameter("AdvMail_ColQuote") & UploadFormRequest("RG_recordId") & getAdvMailPlugInParameter("AdvMail_ColQuote")
	Set Conn = Server.CreateObject("AdoDb.Connection")
	Conn.Open getAdvMailPlugInParameter("AdvMail_editConnection")
	on error resume next
	Conn.execute (RG_editQuery)
	if err.number<>0 then
		FirstError = err.Description
		err.clear
		RG_editQuery = replace(replace(RG_editQuery,"[",""),"]","")
		Conn.execute (RG_editQuery)
		if err.number<>0 then
			err.clear
			RG_editQuery = replace(replace(RG_editQuery,"[","`"),"]","`")
			Conn.execute (RG_editQuery)
			if err.number<>0 then
				response.write "I find an error in the sql:<br>" & replace(replace(RG_editQuery,"`",""),"`","") & "<br>" & "I find this error: " & FirstError
				response.end
			end if
		end if
	end if
	on error goto 0
			
	Conn.close
	Set Conn = nothing
	
end function


function deleteFromSendMail
		
	if getAdvMailPlugInParameter("AdvMail_FilesToDelete") <> "" then
		DW_selectQuery = "SELECT * from " & getAdvMailPlugInParameter("AdvMail_editTable") & " where " & getAdvMailPlugInParameter("AdvMail_col") & " = " & getAdvMailPlugInParameter("AdvMail_RecordId")
		
		Set DW_Conn = Server.CreateObject("AdoDb.Connection")
		Set DW_Rec = Server.CreateObject("AdoDb.RecordSet")
		DW_Conn.Open getAdvMailPlugInParameter("AdvMail_editConnection")
		DW_Rec.open DW_selectQuery, DW_Conn
		DW_File = split(getAdvMailPlugInParameter("AdvMail_FilesToDelete"),",")
		set DW_Fs = server.CreateObject("Scripting.FileSystemObject")
		for DW_x = 0 to ubound(DW_File)
			DW_FileDel = DW_Rec(DW_File(DW_x))
			if DW_FileDel<>"" and not isnull(DW_FileDel) then
				if instr(DW_FileDel,":\")>0 then
					DW_FilePath = DW_FileDel
				else
					DW_FilePath = server.MapPath(DW_FileDel)
				end if
				if DW_Fs.fileExists(DW_FilePath) then
					set DW_f = DW_Fs.getFile(DW_FilePath)
					DW_f.delete
					'delete the thumbnails
					if getAdvMailPlugInParameter("AdvMail_ThumbSuffix") <> "" then
						if DW_Fs.fileExists(getThumbNameMail(DW_FilePath,"after",getAdvMailPlugInParameter("AdvMail_ThumbSuffix"))) then
							set DW_f = DW_Fs.getFile(getThumbNameMail(DW_FilePath,"after",getAdvMailPlugInParameter("AdvMail_ThumbSuffix")))
							DW_f.delete
						end if
						if DW_Fs.fileExists(getThumbNameMail(DW_FilePath,"before",getAdvMailPlugInParameter("AdvMail_ThumbSuffix"))) then
							set DW_f = DW_Fs.getFile(getThumbNameMail(DW_FilePath,"before",getAdvMailPlugInParameter("AdvMail_ThumbSuffix")))
							DW_f.delete
						end if
					end if
				end if
			end if
		next			
		DW_Rec.close
		DW_Conn.close
		set DW_Fs = nothing
	end if	
	
	DW_editQuery = "delete from " & getAdvMailPlugInParameter("AdvMail_editTable") & " where " & getAdvMailPlugInParameter("AdvMail_col") & " = " & getAdvMailPlugInParameter("AdvMail_RecordId")

    ' execute the delete
    Set DW_editCmd = Server.CreateObject("ADODB.Command")
    DW_editCmd.ActiveConnection = getAdvMailPlugInParameter("AdvMail_editConnection")
    DW_editCmd.CommandText = DW_editQuery
    DW_editCmd.Execute
    DW_editCmd.ActiveConnection.Close
	
end function

function isSingleMailRecord()
	tmp = split(getAdvMailPlugInParameter("AdvMail_Files"),"@_@_@")
	if tmp(1)<>"" then
		if clng(tmp(1)) = 1 then
			ris = -1
		else
			ris = 0
		end if
	else
		ris = -1
	end if
	isSingleMailRecord = ris
end function

function isAdvMailInsert()
	err.clear
	on error resume next
	test = getAdvMailPlugInParameter("AdvMail_AdvMailType")
	if err.number = 0 then
		if test = "Insert" then
			isAdvMailInsert = "-1"
		else
			isAdvMailInsert = "0"
		end if
	else
		isAdvMailInsert = "0"
	end if
	on error goto 0
end function

function isAdvMailUpdate()
	err.clear
	on error resume next
	test = getAdvMailPlugInParameter("AdvMail_AdvMailType")
	if err.number = 0 then
		if test = "Update" then
			isAdvMailUpdate = "-1"
		else
			isAdvMailUpdate = "0"
		end if
	else
		isAdvMailUpdate = "0"
	end if
	on error goto 0
end function

function isAdvMailDelete()
	err.clear
	on error resume next
	test = getAdvMailPlugInParameter("AdvMail_AdvMailType")
	if err.number = 0 then
		if test = "AdvMailDelete" then
			isAdvMailDelete = "-1"
		else
			isAdvMailDelete = "0"
		end if
	else
		isAdvMailDelete = "0"
	end if
	on error goto 0
end function

sub setParamVal_AdvMail()
	if isAdvMailInsert="-1" or isAdvMailUpdate="-1" then
		Set ParamVal_AdvMail = CreateObject("Scripting.Dictionary")
		tmp = split(getAdvMailPlugInParameter("AdvMail_Files"),"@_@_@")
		AdvParamList = split(tmp(0),"|")
		MaxFieldNumberAdv = ubound(ParamList)
		for x=0 to Ubound(AdvParamList)
			TmpVal = Split(AdvParamList(x),";")
			for y=0 to ubound(TmpVal)
				Key = right("00" & cstr(x),3) & cstr(y)
				ParamVal_AdvMail.add Key, TmpVal(y)
			next
		next
	end if
end sub

sub setExtraData()
	tmp = split(RG_MailParameter,"@@@_@@@_@@@")
	NoSendFileExceed = tmp(26)
	TotalFileSize = tmp(25)
	if TotalFileSize = "" then
		TotalFileSize = 0
	end if
end sub

sub createPassword()
	if getAdvMailPlugInParameter("AdvMail_PwdCreate") = "1" then
		select case getAdvMailPlugInParameter("AdvMail_PwdType")
		case "0"
			pwdChar = split("0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z",",")
		case "1"
			pwdChar = split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z",",")
		case else
			pwdChar = split("0,1,2,3,4,5,6,7,8,9",",")
		end select
		Randomize
    	newPassword = ""
	    While Len(newPassword) < clng(getAdvMailPlugInParameter("AdvMail_PwdLength"))
        	newPassword = newPassword & pwdChar(Abs(Int(-(Rnd() * ubound(pwdChar)))))
	    Wend
	end if	
end sub

sub verifyUserExists()
	if isAdvMailInsert = "-1" then
		if getAdvMailPlugInParameter("AdvMail_CheckUserName") <> "" then
			Set Conn = Server.CreateObject("AdoDb.Connection")
			Set RG_Rec = Server.CreateObject("AdoDb.Recordset")
			Conn.Open getAdvMailPlugInParameter("AdvMail_editConnection")
			fieldName = ""
			tmpDbField = split(getAdvMailPlugInParameter("AdvMail_columnsStr"),"|")
			tmpFormField = split(getAdvMailPlugInParameter("AdvMail_fieldsStr"),"|")
			for J=0 to ubound(tmpFormField) step 2
				if ucase(tmpFormField(J)) = ucase(getAdvMailPlugInParameter("AdvMail_CheckUserName")) then
					fieldName = tmpDbField(J)
					exit for
				end if
			next
			SQL = "SELECT " & verFieldTableName(fieldName) & " from " & verFieldTableName(getAdvMailPlugInParameter("AdvMail_editTable")) & " where " & verFieldTableName(fieldName) & " = '" & Replace(UploadFormRequest(getAdvMailPlugInParameter("AdvMail_CheckUserName")),"'","''") & "'"
			RG_Rec.open SQL,Conn
			esiste = 0
			If Not RG_Rec.EOF Or Not RG_Rec.BOF Then 
				esiste = -1
			end if
			Conn.close
			Set Conn = nothing
			
			if esiste = -1 then
				tmpPar = split(RG_MailParameter,"@@@_@@@_@@@")
				valueToRedirectSend = tmpPar(24)
				
				newPage = "<html><head><script language=" & chr(34) & "JavaScript" & chr(34) & ">function sendForm(){myForm.submit();}</script></head><body onLoad=" & chr(34) & "sendForm()" & chr(34) & ">" & vbcrlf
				newPage = newPage & "<form action=" & chr(34) & getAdvMailPlugInParameter("AdvMail_RedirectUserExists") & chr(34) & " method=" & chr(34) & tmpPar(27) & chr(34) & " name=" & chr(34) & "myForm" & chr(34) & ">" & vbcrlf
				
				if valueToRedirectSend <> "" then
					listToSend = split(valueToRedirectSend,"|")
					for x = 0 to ubound(listToSend)
						newPage = newPage & "<input name=" & chr(34) & listToSend(x) & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & UploadFormRequest(listToSend(x)) & chr(34) & ">" & vbcrlf
					next
				end if
				newPage = newPage & "<input name=" & chr(34) & "dwzUserExist" & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & "yes" & chr(34) & ">" & vbcrlf
				newPage = newPage & "<input name=" & chr(34) & "requsername" & chr(34) & " type=" & chr(34) & "hidden" & chr(34) & " value=" & chr(34) & UploadFormRequest(getAdvMailPlugInParameter("AdvMail_CheckUserName")) & chr(34) & ">" & vbcrlf
				
				newPage = newPage & "</form></body></html>"
				response.write(newPage)
				response.End()
			end if
			
		end if
	end if	
end sub

function getThumbNameMail(n,where,prefix)
	path = left(n,instrRev(n,"\"))
	ext = mid(n,instrRev(n,"."))
	nome = replace(left(n,instrRev(n,".")-1),path,"")
	if where = "after" then
		getThumbNameMail = path & nome & prefix & ext
	else
		getThumbNameMail = path & prefix & nome & ext
	end if
end function

function advMailWriteLog(sWriteLog, sLogFileType, sPathLog, sLogText)
	if sLogFileType = "d" then
		LogName = year(Date) & right("0" & month(date), 2) & right("0" & day(date), 2) & ".txt"
	else
		LogName = year(Date) & right("0" & month(date), 2) & ".txt"
	end if
	FullPath = server.MapPath(sPathLog & LogName)
	set logFs = server.CreateObject("Scripting.FileSystemObject")
	Application.Lock()
	if logFs.FileExists(FullPath) then
		set myFile = logFs.OpenTextFile(FullPath, 8)
	else
		set myFile = logFs.OpenTextFile(FullPath, 2, true)
	end if
	myFile.Write(sLogText)
	myFile.close
	Application.UnLock()
	set logFs = nothing
end function

function advMailRegSendMail(sTable, sField)
	tmpFieldText = ""
	tmpValueText = ""
	tmpField = split(sField, "|")
	for x=0 to ubound(tmpField)
		tmp = split(tmpField(x), ";")
		sValore = getValue(tmp(1) & "@_rec_@")
		typeArray = Split(tmp(2),",")
	    delim = typeArray(0)
		If (delim = "none") Then delim = ""
	    altVal = typeArray(1)
    	If (altVal = "none") Then altVal = ""
	    emptyVal = typeArray(2)
	    If (emptyVal = "none") Then emptyVal = ""
	    If (sValore = "") Then
	    	sValore = emptyVal
    	Else
      		If (altVal <> "") Then
		        sValore = altVal
      		ElseIf (delim = "'") Then  ' escape quotes
        		sValore = "'" & Replace(sValore,"'","''") & "'"
      		Else
        		sValore = delim & sValore & delim
      		End If
    	End If
		
		if tmpFieldText = "" then
			tmpFieldText = tmp(0)
		else
			tmpFieldText = tmpFieldText & "," & tmp(0)
		end if
		if tmpValueText = "" then
			tmpValueText = sValore
		else
			tmpValueText = tmpValueText & "," & sValore
		end if
	next	
	StrSQL = "insert into " & sTable & " (" & tmpFieldText & ") values (" & tmpValueText & ")"
	Conn.execute StrSQL	
end function


function dwz_DoDateTime(str, nNamedFormat, nLCID)				
	dim strRet, nOldLCID
	strRet = str
	If (nLCID > -1) Then
		oldLCID = Session.LCID
	End If
	On Error Resume Next
	If (nLCID > -1) Then							
		Session.LCID = nLCID
	End If
	If ((nLCID < 0) Or (Session.LCID = nLCID)) Then
		strRet = FormatDateTime(str, nNamedFormat)
	End If
	If (nLCID > -1) Then
		Session.LCID = oldLCID
	End If
	dwz_DoDateTime = strRet
End Function

function dwz_pause(sec)
	startDate = now
	do while 1
		if dateAdd("s",sec,startDate) < now then
			exit do
		end if
	loop
end function

function requestStopSend()
	Set FS = CreateObject("Scripting.FileSystemObject")
	TempFileName = getTempFolder() & "\ms" & SendMailID & "_stop.~tmp"
	if FS.FileExists(TempFileName) then
		on error resume next
		FS.DeleteFile(TempFileName)
		on error goto 0
		requestStopSend = true
	else
		requestStopSend = false
	end if
	set Fs = nothing
end function


%>

Anon7 - 2021