trigger an event when an email is SENT

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

trigger an event when an email is SENT

Post by naren » 2019-04-30 09:15

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.

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

Re: trigger an event when an email is SENT

Post by mattg » 2019-04-30 09:31

Use a global rule to catch the message then call a function as one of the actions
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-01 05:12

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.

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

Re: trigger an event when an email is SENT

Post by mattg » 2019-05-01 05:32

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
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-01 08:10

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 ?

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

Re: trigger an event when an email is SENT

Post by mattg » 2019-05-01 08:16

from contains '@example.com'

if multiple domains use OR with multiple criteria
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-01 08:28

Great. Thank you @mattg. This should work.

Thank you.

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-01 09:20

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 ?

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

Re: trigger an event when an email is SENT

Post by mattg » 2019-05-01 10:54

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
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 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 ?

User avatar
SorenR
Senior user
Senior user
Posts: 3183
Joined: 2006-08-21 15:38
Location: Denmark

Re: trigger an event when an email is SENT

Post by SorenR » 2019-05-02 08:58

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.
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-02 09:21

this event will be active for all the users.

User avatar
SorenR
Senior user
Senior user
Posts: 3183
Joined: 2006-08-21 15:38
Location: Denmark

Re: trigger an event when an email is SENT

Post by SorenR » 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?
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

User avatar
SorenR
Senior user
Senior user
Posts: 3183
Joined: 2006-08-21 15:38
Location: Denmark

Re: trigger an event when an email is SENT

Post by SorenR » 2019-05-02 13:19

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:
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-03 04:17

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.

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

Re: trigger an event when an email is SENT

Post by mattg » 2019-05-03 05:05

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?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-03 05:20

we need to read the SENT message_id for our implementation.

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

Re: trigger an event when an email is SENT

Post by mattg » 2019-05-03 07:27

Yes you keep saying that, but why?
What is the use case?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 3183
Joined: 2006-08-21 15:38
Location: Denmark

Re: trigger an event when an email is SENT

Post by SorenR » 2019-05-03 07:42

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 ??
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

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

Re: trigger an event when an email is SENT

Post by mattg » 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...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 3183
Joined: 2006-08-21 15:38
Location: Denmark

Re: trigger an event when an email is SENT

Post by SorenR » 2019-05-03 12:45

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 ...
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

naren
New user
New user
Posts: 14
Joined: 2019-04-30 09:01

Re: trigger an event when an email is SENT

Post by naren » 2019-05-03 17:04

Thank you @mattg and @SorenR.

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

Post Reply