Page 1 of 1

trigger an event when an email is SENT

Posted: 2019-04-30 09:15
by naren
How to write script to trigger an event when an email is SENT from an account.
The basic scenario is, i want to do some operation when an email was SENT to an external account using hmailserver. but i am not able to find an event which triggers/fires when an email was SENT.

(or)

Is there a way to find out the type of an email whether it's SENT/RECEIVED in any of the events in EventHandler.Vb ?

Thanks.

Re: trigger an event when an email is SENT

Posted: 2019-04-30 09:31
by mattg
Use a global rule to catch the message then call a function as one of the actions

Re: trigger an event when an email is SENT

Posted: 2019-05-01 05:12
by naren
Thanks for the reply @mattg.

I am not sure how to create global rule and then call a function. if possible can please share some example.

Re: trigger an event when an email is SENT

Posted: 2019-05-01 05:32
by mattg
In the admin GUI
Rules >> Add

criteria
from contains 'me@example.com'

action
Run Function 'MyFunction'



In your eventhandlers add

Sub MyFunction(oMessage)
'do stuff here
end sub

In admin GUI enable scripts

Re: trigger an event when an email is SENT

Posted: 2019-05-01 08:10
by naren
But this global rule will apply only for one account(me@example.com). But in my scenario, we need this functionality for all the accounts.
So how to create a global rule for all the accounts which will trigger a function when an email was SENT ?

Re: trigger an event when an email is SENT

Posted: 2019-05-01 08:16
by mattg
from contains '@example.com'

if multiple domains use OR with multiple criteria

Re: trigger an event when an email is SENT

Posted: 2019-05-01 08:28
by naren
Great. Thank you @mattg. This should work.

Thank you.

Re: trigger an event when an email is SENT

Posted: 2019-05-01 09:20
by naren
This worked.

Now i am able to trigger an event on email SENT
But, oMessage.ID is always returning the MessageID of message corresponding to INBOX folder.
How to get the MessageID of SENT folder ?

Re: trigger an event when an email is SENT

Posted: 2019-05-01 10:54
by mattg
Messages are added to SENT by an IMAP client, the actual messages are sent via SMTP

Catching when an IMAP client logs in is much trickier

Re: trigger an event when an email is SENT

Posted: 2019-05-02 08:34
by naren
we would require to read the SENT message_id to continue our implementation.

Can you please let us know how proceed further on this ?

Re: trigger an event when an email is SENT

Posted: 2019-05-02 08:58
by SorenR
naren wrote:
2019-05-02 08:34
we would require to read the SENT message_id to continue our implementation.

Can you please let us know how proceed further on this ?
Are your clients required to authenticate with the server to send emails?

Is this "event" active for all users or only single domains?

Accessing a "sent mail" is really a R/O operation as you cannot legally change anything!

There may be multiple ways to do this pending your answers.

Re: trigger an event when an email is SENT

Posted: 2019-05-02 09:21
by naren
this event will be active for all the users.

Re: trigger an event when an email is SENT

Posted: 2019-05-02 10:04
by SorenR
naren wrote:
2019-05-02 09:21
this event will be active for all the users.
Do you need to modify the message before delivery or is it only for reference?

Re: trigger an event when an email is SENT

Posted: 2019-05-02 13:19
by SorenR
Hmm... This is like me driving to town on weekends... I'll be running all the red lights and not using my turn signals - I'm not coming to town to watch the coloured lights and it's nobody's business where I'm going... :roll:

Re: trigger an event when an email is SENT

Posted: 2019-05-03 04:17
by naren
SorenR wrote:
2019-05-02 10:04
naren wrote:
2019-05-02 09:21
this event will be active for all the users.
Do you need to modify the message before delivery or is it only for reference?
we just want to read the message headers for mapping and store the message in data base.

Re: trigger an event when an email is SENT

Posted: 2019-05-03 05:05
by mattg
Then why can't you do that from the SMTP message that is passing through?
Why do you need the copy placed in the SENT folder?

Re: trigger an event when an email is SENT

Posted: 2019-05-03 05:20
by naren
we need to read the SENT message_id for our implementation.

Re: trigger an event when an email is SENT

Posted: 2019-05-03 07:27
by mattg
Yes you keep saying that, but why?
What is the use case?

Re: trigger an event when an email is SENT

Posted: 2019-05-03 07:42
by SorenR
mattg wrote:
2019-05-03 07:27
Yes you keep saying that, but why?
What is the use case?
I'm thinking vbscript OnAcceptMessage() and check for oMessage.FromAddress = user@domain and then do stuff to/with email ...OR... global rule if from = xxxx then forward copy to "carboncopy@mydomain.tld" and have an account rule run function on email ??

Re: trigger an event when an email is SENT

Posted: 2019-05-03 08:47
by mattg
The thing is that I can copy mail to a sent folder without actually sending the mail, I can also turn off adding to a a sent folder in my mail client, or changing the folder.

My various mail clients all use a different 'sent' folder each by default, so I have a sent from my iphone, sent form desktop, and sent from my webmail folder

Also, I could name my sent folder 'banana' and set my mail client to save sent messages there.

The only way that I could see this to be done is to search for all folders named 'sent' (or 'banana') and trawl through each of the messages one at a time, much like the delete script does...

Re: trigger an event when an email is SENT

Posted: 2019-05-03 12:45
by SorenR
mattg wrote:
2019-05-03 08:47
The thing is that I can copy mail to a sent folder without actually sending the mail, I can also turn off adding to a a sent folder in my mail client, or changing the folder.

My various mail clients all use a different 'sent' folder each by default, so I have a sent from my iphone, sent form desktop, and sent from my webmail folder

Also, I could name my sent folder 'banana' and set my mail client to save sent messages there.

The only way that I could see this to be done is to search for all folders named 'sent' (or 'banana') and trawl through each of the messages one at a time, much like the delete script does...
or catch it on the way out ...

Re: trigger an event when an email is SENT

Posted: 2019-05-03 17:04
by naren
Thank you @mattg and @SorenR.

I think for now we will go with global rule if from...
Hopefully this should solve our issue.