Clear Information on Run program in Rules

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
plavielle
New user
New user
Posts: 3
Joined: 2020-02-11 19:39

Clear Information on Run program in Rules

Post by plavielle » 2020-02-11 23:13

Hi community.

Can someone make a contribution to explain exactly how to configure and use script in rules. I use the latest stable version download today and after many test i can just make this working (i search to save attachement directly to disk)

https://stackoverflow.com/questions/321 ... s/49324125

I dont know why i cannot use "SaveAttachments" in "run action" in rule definition.

How i can make it work.

In rule i just check that mail come from a specific address.

Thanks for your help.

User avatar
mattg
Moderator
Moderator
Posts: 21103
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Clear Information on Run program in Rules

Post by mattg » 2020-02-11 23:23

plavielle wrote:
2020-02-11 23:13
I dont know why i cannot use "SaveAttachments" in "run action" in rule definition.
Because 'SaveAttachments' isn't an option there....


I have this in my eventhandlers.vbs

Code: Select all

Function SaveAttachments(oMessage)
	dim i, aPath
	dim fileout, FSO1, OBJoutfile, FSO, f

	Set oApp = CreateObject("hMailServer.Application")
	' Give this script permission to access all
	' hMailServer settings.
	Call oApp.Authenticate("Administrator", "TopSecretPassword")

	fileout = oapp.Settings.Directories.LogDirectory & "\Saved Files.log"
	Set FSO1 = CreateObject("Scripting.FileSystemObject")
	set OBJoutfile = FSO1.opentextfile(fileout,8,1)

	for i = 1 to oMessage.attachments.count ' attachment
		aPath = oApp.Settings.Directories.TempDirectory & "\AttachmentDropFolder\" & oMessage.ID & "-" & oMessage.attachments.item(i-1).Filename
		oMessage.attachments.item(i-1).saveAs(aPath)
		OBJoutfile.writeline now & "  " & aPath
	next 'i - attachment
	set OBJOutFile = Nothing
End Function

This is called from an account level rule, with the action 'Run Function' pointing to 'SaveAttachments'
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

mikedibella
Normal user
Normal user
Posts: 230
Joined: 2016-12-08 02:21

Re: Clear Information on Run program in Rules

Post by mikedibella » 2020-02-12 00:19

I use this script function reformat SMS messages coming from certain cellular carriers. These carriers attach the body of the SMS as an attachment to an email.

Code: Select all

Sub AppendAttachment(oMessage)
	if oMessage.Subject = "" then 
		oMessage.Subject = "SMS Message"
	end if
	if oMessage.Attachments.Count > 0 then
		' save attachment to temporary file
		set oFileSys = CreateObject("Scripting.FileSystemObject")
		sTempFile = oFileSys.GetSpecialFolder(2) & oFileSys.GetTempName
		oMessage.Attachments.Item(0).SaveAs sTempFile
		' read attachment to string
		set fAttachment = oFileSys.OpenTextFile(sTempFile, 1)
		sText = fAttachment.ReadAll
		fAttachment.Close
		oFileSys.DeleteFile sTempFile
		oMessage.Attachments.Item(0).Delete
		' append attachment to message body
		oMessage.Body = oMessage.Body & sText
	end if
	oMessage.Save
End Sub
Attachments
rule.png
rule.png (11.63 KiB) Viewed 3226 times

plavielle
New user
New user
Posts: 3
Joined: 2020-02-11 19:39

Re: Clear Information on Run program in Rules

Post by plavielle » 2020-02-12 08:35

Thanks Mattg and mikedibella.

Mattg i think i have tested this with no result, but i'm going to re-test.

I have tested to put in eventhandler just a sub that write something in log file (like i see somewhere in forum or doc) and nothing.

Perhaps my rule is not correctly write, but when i put email address in "test" it says me ok.

I'm going to test in 1 hour and put a message to says if ok.

Thanks for your help.

User avatar
mattg
Moderator
Moderator
Posts: 21103
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Clear Information on Run program in Rules

Post by mattg » 2020-02-12 10:14

you need to enable eventhandler.vbs by enabling scripts

The eventhandlers.vbs needs to be in the default location
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

plavielle
New user
New user
Posts: 3
Joined: 2020-02-11 19:39

Re: Clear Information on Run program in Rules

Post by plavielle » 2020-02-12 12:50

I finally found the problem.

My goal was to store scan made internal copier directly on file server. The scan are send by mail to user and then hmailserver store attachement on file server.

Before put in place hmailserver, i think that the copier send mail with its proper email address, but it is not the case.

But i think there is something to correct in hmail LOG code : the first image was data from hmail log
pb-mail-1.jpg
The second image is from a free mail client
pb-mail-2.jpg
So, from the beginning i was misled by the configuration of the copier AND by hmail LOG

hmail log says that the mail was FROM "copieurfax@******" but in fact it come FROM "plavielle@**********"

So sorry for this topic, but i think it can be util to someone.

User avatar
mattg
Moderator
Moderator
Posts: 21103
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Clear Information on Run program in Rules

Post by mattg » 2020-02-12 16:16

hmailserver logs show the SMTP envelop FROM and TO which are often different than the message headers
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Post Reply