Local Send Only
-
- Senior user
- Posts: 309
- Joined: 2009-07-21 12:33
Local Send Only
Hi all,
Is it possible to tell hMail to only allow some users in a domain to make internal emails only? So, for example, I have a domain called mydomain.co.uk in hMail that contains three users, usera@, userb@ and userc@.
I want usera@ to be able to send emails to any email account in the world. This is the default, and works great. I want userb@ and userc@, however, to only be able to send emails to mydomain.co.uk accounts.
I originally posted this query in the main forum, and was advised that scripting could do this. I have a reasonable level of VBScripting ability, but wanted to ascertain first as to whether this had come up before and whether or not there was an existing script I could use/modify for my purposes.
Looking at the scripting documentation, I suspect the function I need to be looking at is bool IsLocalUser, which should check to see if the recipient is a local user. I understand the principle that if this check comes back as a non-match, i.e. the user is trying to email an external email account, then the process should be blocked, and, preferably, the user should recieve a notice telling them the email has not been sent and why.
This script would need to be attached to users, rather than IP addresses, since I DHCP all my client machines and a great many people hot-desk, so there's no assurance that a person is at the same desk every time.
Can anybody help with pointing me in the right direction for this, or, if a script like this already exists, could somebody let me know where to find it?
Is it possible to tell hMail to only allow some users in a domain to make internal emails only? So, for example, I have a domain called mydomain.co.uk in hMail that contains three users, usera@, userb@ and userc@.
I want usera@ to be able to send emails to any email account in the world. This is the default, and works great. I want userb@ and userc@, however, to only be able to send emails to mydomain.co.uk accounts.
I originally posted this query in the main forum, and was advised that scripting could do this. I have a reasonable level of VBScripting ability, but wanted to ascertain first as to whether this had come up before and whether or not there was an existing script I could use/modify for my purposes.
Looking at the scripting documentation, I suspect the function I need to be looking at is bool IsLocalUser, which should check to see if the recipient is a local user. I understand the principle that if this check comes back as a non-match, i.e. the user is trying to email an external email account, then the process should be blocked, and, preferably, the user should recieve a notice telling them the email has not been sent and why.
This script would need to be attached to users, rather than IP addresses, since I DHCP all my client machines and a great many people hot-desk, so there's no assurance that a person is at the same desk every time.
Can anybody help with pointing me in the right direction for this, or, if a script like this already exists, could somebody let me know where to find it?
Re: Local Send Only
Try something like this...
(I was intending setting something like this up for my little kids anyway - I'll probably also add an 'approval' requirement to incoming e-mail one day soon)
I have this in OnDeliverMessage, but it doesn't have to be I don't reckon. OnDeliverMessage is silent to the sender...
I also assumed less than 100 such local accounts, and less than 100 recipients per e-mail. You could either change this or perhaps even force this...
(I was intending setting something like this up for my little kids anyway - I'll probably also add an 'approval' requirement to incoming e-mail one day soon)
I have this in OnDeliverMessage, but it doesn't have to be I don't reckon. OnDeliverMessage is silent to the sender...
I also assumed less than 100 such local accounts, and less than 100 recipients per e-mail. You could either change this or perhaps even force this...
Code: Select all
Sub OnDeliverMessage(oMessage)
Dim LocalOnlyAccounts(100)
Dim temprecipients(100)
Dim i, j, k, l
Dim varDomain
Dim varAddress
varDomain = "mydomain.com"
LocalOnlyAccounts(0)= "user1" & "@" & varDomain
LocalOnlyAccounts(1)= "user2" & "@" & varDomain
For i = 0 to uBound(LocalOnlyAccounts)
If oMessage.FromAddress = LocalOnlyAccounts(i) then 'sender is restricted account
for j = 0 to oMessage.recipients.count -1
temprecipients(j) = oMessage.recipients.item(j).address
next 'j
j = 0
k = oMessage.recipients.count -1
while j <= k
If oMessage.recipients.item(j).islocaluser = false then 'remove non-local recipients
l= j
while l < k
temprecipients(l) = temprecipients(l+1)
l=l+1
wend
temprecipients(k) = ""
k=k-1
else
j=j+1
end if
wend
oMessage.clearrecipients()
For j = 0 to k
varAddress = temprecipients(j)
oMessage.AddRecipient "", varAddress
Next 'j
oMessage.save
End if
Next 'i
End Sub
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
-
- Senior user
- Posts: 309
- Joined: 2009-07-21 12:33
Re: Local Send Only
Hmm...I just tried that, putting it into the correct part of my hMail's EventHandlers.vbs script, but nothing.
I changed mydomain.com to be my actual domain in question and changed user1 and user2 to two test users, both still genuine accounts, I have in the domain.
Both test users can still email out to both internal (so <user>@<myrealdomain>) and external (to, for example, my gmail account).
I changed mydomain.com to be my actual domain in question and changed user1 and user2 to two test users, both still genuine accounts, I have in the domain.
Both test users can still email out to both internal (so <user>@<myrealdomain>) and external (to, for example, my gmail account).
Re: Local Send Only
Did you get an error log created?
Also, do you have a default domain set?
Also, do you have a default domain set?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
-
- Senior user
- Posts: 309
- Joined: 2009-07-21 12:33
Re: Local Send Only
No error log that I can see. Er...excuse my ignorance, default domain set...?mattg wrote:Did you get an error log created?
Also, do you have a default domain set?
Re: Local Send Only
logs are typically in C:\Program files\hmailserver\logs but this can be changed within your hmailserver.ini
The error log will be named like 'ERROR_hmailserver_DATE.log'
A default domain is set in the hMailserver Administrator under Settings >> Advanced
This is blank by default, but you may have added a domain name.
Can you show your entire EventHandler.vbs?
Also, did you enable scripts, reload the script and then check syntax? Was there any errors?
The error log will be named like 'ERROR_hmailserver_DATE.log'
A default domain is set in the hMailserver Administrator under Settings >> Advanced
This is blank by default, but you may have added a domain name.
Can you show your entire EventHandler.vbs?
Also, did you enable scripts, reload the script and then check syntax? Was there any errors?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
-
- Senior user
- Posts: 309
- Joined: 2009-07-21 12:33
Re: Local Send Only
No errors listed.mattg wrote:logs are typically in C:\Program files\hmailserver\logs but this can be changed within your hmailserver.ini
The error log will be named like 'ERROR_hmailserver_DATE.log'
Ok, mine is indeed blank.mattg wrote:A default domain is set in the hMailserver Administrator under Settings >> Advanced
This is blank by default, but you may have added a domain name.
Sure. Here you go:mattg wrote:Can you show your entire EventHandler.vbs?
Code: Select all
' Sub OnClientConnect(oClient)
' End Sub
' Sub OnAcceptMessage(oClient, oMessage)
' End Sub
' Sub OnDeliveryStart(oMessage)
' End Sub
Sub OnDeliverMessage(oMessage)
Dim LocalOnlyAccounts(100)
Dim temprecipients(100)
Dim i, j, k, l
Dim varDomain
Dim varAddress
varDomain = "mydomain.com"
LocalOnlyAccounts(0)= "user1" & "@" & varDomain
LocalOnlyAccounts(1)= "user2" & "@" & varDomain
For i = 0 to uBound(LocalOnlyAccounts)
If oMessage.FromAddress = LocalOnlyAccounts(i) then 'sender is restricted account
for j = 0 to oMessage.recipients.count -1
temprecipients(j) = oMessage.recipients.item(j).address
next 'j
j = 0
k = oMessage.recipients.count -1
while j <= k
If oMessage.recipients.item(j).islocaluser = false then 'remove non-local recipients
l= j
while l < k
temprecipients(l) = temprecipients(l+1)
l=l+1
wend
temprecipients(k) = ""
k=k-1
else
j=j+1
end if
wend
oMessage.clearrecipients()
For j = 0 to k
varAddress = temprecipients(j)
oMessage.AddRecipient "", varAddress
Next 'j
oMessage.save
End if
Next 'i
End Sub
' Sub OnBackupFailed(sReason)
' End Sub
' Sub OnBackupCompleted()
' End Sub
' Sub OnError(iSeverity, iCode, sSource, sDescription)
' End Sub
' Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
' End Sub
I can confirm that my test users can still email both internal and external addresses.
Enabled, Reloaded and Checked. No errors.mattg wrote:Also, did you enable scripts, reload the script and then check syntax? Was there any errors?
I have also set Logging on whilst testing, and can see my outgoing mail being smoothly handled by hMail as its sent, just as it is with any genuine user, which leads to to believe that perhaps the script is fine but it's not properly activated?
-
- Senior user
- Posts: 309
- Joined: 2009-07-21 12:33
Re: Local Send Only
***UPDATE*** Ah ha! I restarted hMail, made sure the script was there, Enabled and Reloaded then tried again and it looks like it's working fine!
My test user can currently email to @mydomain.com accounts, which is correct, but an email to my external gMail account still isn't as having as having arrived, which was sent about 10 minutes ago!
mattg, you are an absolute star, sir!
I did initially want my users to get a message back saying that they couldn't email external accounts when they tried, but I'm guessing I can do this on a user by user basis via rules? Or is it fairly simple to add something to this script that says it?
My test user can currently email to @mydomain.com accounts, which is correct, but an email to my external gMail account still isn't as having as having arrived, which was sent about 10 minutes ago!

mattg, you are an absolute star, sir!
I did initially want my users to get a message back saying that they couldn't email external accounts when they tried, but I'm guessing I can do this on a user by user basis via rules? Or is it fairly simple to add something to this script that says it?
Re: Local Send Only
Do you require SMTP authentication to send from your mailserver in all IP ranges, especially the ranges that the users are located in?
Sorry, I see your update. Great. (I didn't have to restart my server to update the script though...)
You can send a message back to the sender as part of this script. Just create a new message using the information collected. You could incorporate which addresses you have rejected...
I tested with multiple recipients. All local accounts allowed, all external accounts dropped (silently).
If you logging enabled, you will see in the logs where the message is just dropped, or if it is sent to external accounts.
Sorry, I see your update. Great. (I didn't have to restart my server to update the script though...)
You can send a message back to the sender as part of this script. Just create a new message using the information collected. You could incorporate which addresses you have rejected...
I tested with multiple recipients. All local accounts allowed, all external accounts dropped (silently).
If you logging enabled, you will see in the logs where the message is just dropped, or if it is sent to external accounts.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
-
- Senior user
- Posts: 309
- Joined: 2009-07-21 12:33
Re: Local Send Only
Ok, so am I right in thinking that something like this:mattg wrote:You can send a message back to the sender as part of this script. Just create a new message using the information collected. You could incorporate which addresses you have rejected...
Code: Select all
dim oMessage
Set oMessage = CreateObject("hMailServer.Message")
oMessage.From = "Server Admin"
oMessage.FromAddress = "admin@mydomain.com"
oMessage.Subject = "ACtion Disallowed"
oMessage.AddRecipient "Email User", LocalOnlyAccounts(i)
oMessage.Body = "You can only send emails to another @mydomain.com account. Your email has not been sent."
oMessage.Save
In addition, I have a total of 17 users who should be thus affected. I've just listed their section in the code as:
LocalOnlyAccounts(0)=
through to
LocalOnlyAccounts(16)=
rather than using the usual computer convention of entering single digit numbers as 0# (so my list goes (1), (2), (3), rather than (01), (02), (03)). I assume this is fine?
Last edited by Tezcatlipoca on 2010-01-05 17:38, edited 1 time in total.
Re: Local Send Only
Yep exactly like I was playing with, only I have the rejected recipients listed in there too 
It needs to go somewhere where it only fires if a message is rejected, not every time a 'local only user' sends mail...
Also, I got my rejected recipients included and I noticed an error.
It looks like all recipients after the first rejection are thereafter rejected. That's not what I had in mind...

It needs to go somewhere where it only fires if a message is rejected, not every time a 'local only user' sends mail...
Also, I got my rejected recipients included and I noticed an error.
It looks like all recipients after the first rejection are thereafter rejected. That's not what I had in mind...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
So here's my script as it stands now.
It correctly removes non-local recipients and sends a message to the sender telling them what they have done wrong
Edit - changed to ensure that address in any case will be checked as per this thread
It correctly removes non-local recipients and sends a message to the sender telling them what they have done wrong
Code: Select all
Sub OnDeliverMessage(oMessage)
Dim LocalOnlyAccounts(100)
Dim temprecipients(100)
Dim i, j, k, l
Dim varDomain
Dim varAddress
Dim RejectedAddress
varDomain = "domain.com" 'CHANGE ME
LocalOnlyAccounts(0)= "user1" & "@" & varDomain 'CHANGE ME
LocalOnlyAccounts(1)= "user2" & "@" & varDomain 'CHANGE ME
RejectedAddress = ""
For i = 0 to uBound(LocalOnlyAccounts)
If LCase(oMessage.FromAddress) = LocalOnlyAccounts(i) then 'sender is restricted account
for j = 0 to oMessage.recipients.count -1
temprecipients(j) = oMessage.recipients.item(j).address
next 'j
j = 0
k = oMessage.recipients.count -1
while j <= k
If instr(temprecipients(j),"@"& VarDomain) = 0 then 'remove non-local recipients
l= j
RejectedAddress = RejectedAddress & temprecipients(l) & VBNewLine
while l < k
temprecipients(l) = temprecipients(l+1)
l=l+1
wend
temprecipients(k) = ""
k=k-1
else
j=j+1
end if
wend
oMessage.clearrecipients()
For j = 0 to k
varAddress = temprecipients(j)
oMessage.AddRecipient "", varAddress
Next 'j
oMessage.save
End if
Next 'i
If RejectedAddress <> "" then 'we found some invalid recipients
dim oApp, newMessage
dim MessageSubject
dim MessageRecipientAddress
Set oApp = CreateObject("hMailServer.Application")
' Give this script permission to access all
' hMailServer settings.
Call oApp.Authenticate("Administrator", "AdminPassword") 'CHANGE ME
MessageRecipientAddress = oMessage.FromAddress
MessageSubject = "Automatically rejected mail"
Set newMessage = CreateObject("hMailServer.Message")
newMessage.From = "Automated System Mail <admin@yourdomain.com>" 'CHANGE ME
newMessage.FromAddress = "admin@yourdomain.com" 'CHANGE ME
newMessage.Subject = MessageSubject
newMessage.AddRecipient "", MessageRecipientAddress
newMessage.Body = "Your Message with subject " & oMessage.subject & " was not delivered to some recipients due to your account"
newMessage.Body = NewMessage.body & "being limited to only allow mail to be sent to users at " & VarDomain
newMessage.Body = NewMessage.body & vbNewLine & vbNewLine
newMessage.Body = NewMessage.body & "The following recipients did not recieve your e-mail"
newMessage.Body = NewMessage.body & RejectedAddress
newMessage.Save
End if
End Sub
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
-
- Senior user
- Posts: 309
- Joined: 2009-07-21 12:33
Re: Local Send Only
mattg, that is fabulous, thank you
I did have one small problem, but managed to locate it. Basically this line:
newMessage.FromAddress = admin@yourdomain.com
should read
newMessage.FromAddress = "admin@yourdomain.com"
Now my users cannot send out to external addresses, and get a warning message when they try! Thank you!

I did have one small problem, but managed to locate it. Basically this line:
newMessage.FromAddress = admin@yourdomain.com
should read
newMessage.FromAddress = "admin@yourdomain.com"
Now my users cannot send out to external addresses, and get a warning message when they try! Thank you!
Re: Local Send Only
No worries, and I amended the fault you pointed out.Tezcatlipoca wrote:mattg, that is fabulous, thank you![]()
I did have one small problem, but managed to locate it.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
mattg wrote:No worries, and I amended the fault you pointed out.Tezcatlipoca wrote:mattg, that is fabulous, thank you![]()
I did have one small problem, but managed to locate it.
Hi Mattg and Tezcatlipoca
the script works fine, but I have actually another mail server with different domain name and I need to send mail to this domain locally. I create an smtp route and before the script I was send smtp mail perfectly, but now, I cannot, because the script allow only one domain name...or not?
Please can you help me for this case?
Thanks in advance!
Re: Local Send Only
Hi,
It's not my script but 'simple' fix would be to have the meat of the script in select/case statements for each domain but seems the 'proper' fix would be to make varDomain an array & modify parts of script as needed to loop thru (or check if a value is in the array).. Then again perhaps an even simpler 'proper' fix would be to to put the script in your own function, calling it in onDeliverMessage with the domain as a passed in the function call.. There's the winner!
Bill
It's not my script but 'simple' fix would be to have the meat of the script in select/case statements for each domain but seems the 'proper' fix would be to make varDomain an array & modify parts of script as needed to loop thru (or check if a value is in the array).. Then again perhaps an even simpler 'proper' fix would be to to put the script in your own function, calling it in onDeliverMessage with the domain as a passed in the function call.. There's the winner!
Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Local Send Only
Hi all
Thanks for the script. It was quite useful for me.
But, there is another thing. When restricted user send an e-mail, all 'CC/BCC' will changed to 'To'
Is there anyway to change the script?
Thanks
Thanks for the script. It was quite useful for me.
But, there is another thing. When restricted user send an e-mail, all 'CC/BCC' will changed to 'To'
Is there anyway to change the script?
Thanks
Re: Local Send Only
Sure,
You would need to get all recipients as it currently does, and also find out which of these recipients are TO and CC recipients, and when adding them back, add them back as they were previously.
All additional recipients should be BCC recipients.
Feel free to make the changes you need, and please post here if you need help and to post the results of your work so that others can use it.
You would need to get all recipients as it currently does, and also find out which of these recipients are TO and CC recipients, and when adding them back, add them back as they were previously.
All additional recipients should be BCC recipients.
Feel free to make the changes you need, and please post here if you need help and to post the results of your work so that others can use it.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
Hi mattg, so if i want to make 2 domains to "talk" to each other i need a second varDomain correct?
Btw, only one domain is hosted on this hmailserver, the other one is "far far away" lol...
I don´t know shi*t about programing and stuff...
lol, so maybe i will need more help than usual! 
Like this?!
Lol sorry, i´m so lame when it comes to coding 
Btw, only one domain is hosted on this hmailserver, the other one is "far far away" lol...
I don´t know shi*t about programing and stuff...


Like this?!
Code: Select all
Sub OnDeliverMessage(oMessage)
Dim LocalOnlyAccounts(100)
Dim temprecipients(100)
Dim i, j, k, l
Dim varDomain
Dim varDomain2
Dim varAddress
Dim RejectedAddress
varDomain = "domain.com" 'CHANGE ME
varDomain2 = "domain2.com"
LocalOnlyAccounts(0)= "user1" & "@" & varDomain 'CHANGE ME
LocalOnlyAccounts(1)= "user2" & "@" & varDomain 'CHANGE ME
LocalOnlyAccounts(1)= "user1" & "@" & varDomain2 'CHANGE ME
LocalOnlyAccounts(1)= "user2" & "@" & varDomain2 'CHANGE ME
RejectedAddress = ""
For i = 0 to uBound(LocalOnlyAccounts)
If LCase(oMessage.FromAddress) = LocalOnlyAccounts(i) then 'sender is restricted account
for j = 0 to oMessage.recipients.count -1
temprecipients(j) = oMessage.recipients.item(j).address
next 'j
j = 0
k = oMessage.recipients.count -1
while j <= k
If instr(temprecipients(j),"@"& VarDomain, varDomain2) = 0 then 'remove non-local recipients
l= j
RejectedAddress = RejectedAddress & temprecipients(l) & VBNewLine
while l < k
temprecipients(l) = temprecipients(l+1)
l=l+1
wend
temprecipients(k) = ""
k=k-1
else
j=j+1
end if
wend
oMessage.clearrecipients()
For j = 0 to k
varAddress = temprecipients(j)
oMessage.AddRecipient "", varAddress
Next 'j
oMessage.save
End if
Next 'i
If RejectedAddress <> "" then 'we found some invalid recipients
dim oApp, newMessage
dim MessageSubject
dim MessageRecipientAddress
Set oApp = CreateObject("hMailServer.Application")
' Give this script permission to access all
' hMailServer settings.
Call oApp.Authenticate("Administrator", "AdminPassword") 'CHANGE ME
MessageRecipientAddress = oMessage.FromAddress
MessageSubject = "Automatically rejected mail"
Set newMessage = CreateObject("hMailServer.Message")
newMessage.From = "Automated System Mail <admin@yourdomain.com>" 'CHANGE ME
newMessage.FromAddress = "admin@yourdomain.com" 'CHANGE ME
newMessage.Subject = MessageSubject
newMessage.AddRecipient "", MessageRecipientAddress
newMessage.Body = "Your Message with subject " & oMessage.subject & " was not delivered to some recipients due to your account"
newMessage.Body = NewMessage.body & "being limited to only allow mail to be sent to users at " & VarDomain varDomain2
newMessage.Body = NewMessage.body & vbNewLine & vbNewLine
newMessage.Body = NewMessage.body & "The following recipients did not recieve your e-mail"
newMessage.Body = NewMessage.body & RejectedAddress
newMessage.Save
End if
End Sub

Re: Local Send Only
That's apparentssabbath wrote:I don´t know shi*t about programing and stuff...lol, so maybe i will need more help than usual! :
Not many people here will write VB code for just because you can't
There is ONLY one line you need to change, and it is this one (It tests who the message is for)
Code: Select all
If instr(temprecipients(j),"@"& VarDomain) = 0 then 'remove non-local recipients
Code: Select all
If instr(temprecipients(j),"@"& VarDomain) + instr(temprecipients(j),"@"& "domain.com") = 0 then 'remove non-allowed recipients
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
Ok. Thanks. Will try that out and understand a little more.
Will try to read and learn some VB in the next days!
Will try to read and learn some VB in the next days!
Re: Local Send Only
HI,mattg
with your code
oMessage.clearrecipients()
For j = 0 to k
varAddress = temprecipients(j)
oMessage.AddRecipient "", varAddress
Next 'j
oMessage.save
question:
if temprecipients(j)=nothing (all recipients are not local users),so your code will be like this:
oMessage.clearrecipients()
oMessage.save
is that ok?
if temprecipients=nothing, I think it would be better to delete omessage directly
but i don't know how to delete the omessage on (Sub OnDeliverMessage(oMessage)) directly,please help me ,thanks
with your code
oMessage.clearrecipients()
For j = 0 to k
varAddress = temprecipients(j)
oMessage.AddRecipient "", varAddress
Next 'j
oMessage.save
question:
if temprecipients(j)=nothing (all recipients are not local users),so your code will be like this:
oMessage.clearrecipients()
oMessage.save
is that ok?
if temprecipients=nothing, I think it would be better to delete omessage directly
but i don't know how to delete the omessage on (Sub OnDeliverMessage(oMessage)) directly,please help me ,thanks
Re: Local Send Only
I think sohappylcg wrote:is that ok?
That's the point of the script isn't it? to not allow sending to External recipients.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
thanks
So you would say that call all recipients equal delete the message directly?
i wish i know the Omessage has been clear call recipients,but it will be saved on the server still?
So you would say that call all recipients equal delete the message directly?
i wish i know the Omessage has been clear call recipients,but it will be saved on the server still?
Re: Local Send Only
Yes I think the message gets dropped and an error is logged (No remaining recipients)
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
thanks
I make some tests ,but i don't understand the tests result
test1:
the result shows'
1.Mysql added one record
2.hmailserver\logs\ERROR_hmailserver receive the Error information like " No remaining recipients " (just as you said)
i can understand this test result ...but test2……
'----------------------------------
test2:
the result shows:
1.Mysql added many records ,no endless. I have to disable script to stop it add more records to mysql
2.hmailserver\logs\ERROR_hmailserver ...no any error info
i don't understand the result :no error infomation ,and method "ExcuteSql" excute many times ,it means "OnDeliverMessage" excute manys times after "oMessage.clearrecipients " ,why ?
is it while "oMessage.clearrecipients" ,Hmailserver send error info by mail to sender? so excute the method of "OnDeliverMessage" again?
if yes ,mail sender will receive some error info,so i change script like this:
(is it while oMessage.clearrecipients,Hmailserver send error info to sender? so excute the method of "OnDeliverMessage" again?)
when i change to script (do not clear recipients after first time ),but i don't receive any error mail from hmailserver also..
by the way ,after i change the script . mysql only have two records.. no "Mysql added many records ,no endless "
I make some tests ,but i don't understand the tests result
test1:
Code: Select all
Sub OnAcceptMessage(oClient, oMessage)
call ExcuteSql("insert into Mtable (record) values (" recorded") ) 'this method used for record how many times on OnAcceptMessage when send an email
oMessage.clearrecipients
End Sub
1.Mysql added one record
2.hmailserver\logs\ERROR_hmailserver receive the Error information like " No remaining recipients " (just as you said)
i can understand this test result ...but test2……
'----------------------------------
test2:
Code: Select all
Sub OnDeliverMessage(oMessage)
call ExcuteSql("insert into Mtable (record) values (" recorded") ) 'this method used for record how many times on OnDeliverMessage when send an email
oMessage.clearrecipients
End Sub
1.Mysql added many records ,no endless. I have to disable script to stop it add more records to mysql
2.hmailserver\logs\ERROR_hmailserver ...no any error info
i don't understand the result :no error infomation ,and method "ExcuteSql" excute many times ,it means "OnDeliverMessage" excute manys times after "oMessage.clearrecipients " ,why ?
is it while "oMessage.clearrecipients" ,Hmailserver send error info by mail to sender? so excute the method of "OnDeliverMessage" again?
if yes ,mail sender will receive some error info,so i change script like this:
Code: Select all
Sub OnDeliverMessage(oMessage)
set RsqlInfo=Rsql("select * from Mtable where record='recorded'") ' this function "Rsql" is used for get the records from mysql
if RsqlInfo.Eof then 'have no record on mysql ,it means this is the first time to record. if not the first time ,do not clear recipients.
oMessage.clearrecipients
end if
call ExcuteSql("insert into Mtable (record) values (" recorded") 'this method used for record how many times on OnDeliverMessage when send an email
end sub
(is it while oMessage.clearrecipients,Hmailserver send error info to sender? so excute the method of "OnDeliverMessage" again?)
when i change to script (do not clear recipients after first time ),but i don't receive any error mail from hmailserver also..
by the way ,after i change the script . mysql only have two records.. no "Mysql added many records ,no endless "
Re: Local Send Only
because you need to addhappylcg wrote: i don't understand the result :no error infomation ,and method "ExcuteSql" excute many times ,it means "OnDeliverMessage" excute manys times after "oMessage.clearrecipients " ,why ?
oMessage.save
or the message won't be saved after you clear the recipients, ie the message will still have all recipients
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
ok
but i have new doubts
obove 2 method...
just you said,if did not add omessage.save,,,the message will not clear the recipients finally...
so ,i should receive the email...
but acutally ,i did not receive the mail after add "oMessage.ClearRecipients" (but no omessage.save)
why?
but i have new doubts
Code: Select all
test1:
Sub OnAcceptMessage(oClient, oMessage)
oMessage.ClearRecipients
End Sub
Code: Select all
test2:
Sub OnDeliverMessage(oMessage)
oMessage.ClearRecipients
End Sub
obove 2 method...
just you said,if did not add omessage.save,,,the message will not clear the recipients finally...
so ,i should receive the email...
but acutally ,i did not receive the mail after add "oMessage.ClearRecipients" (but no omessage.save)
why?
Re: Local Send Only
happylcg wrote:i don't understand the result :no error infomation ,and method "ExcuteSql" excute many times ,it means "OnDeliverMessage" excute manys times after "oMessage.clearrecipients " ,why ?
OK I'm confusedhappylcg wrote:just you said,if did not add omessage.save,,,the message will not clear the recipients finally...
so ,i should receive the email...
but acutally ,i did not receive the mail after add "oMessage.ClearRecipients" (but no omessage.save)
Which is correct?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
sorry,my english is bad
i explain my question again
test:
after i send an mail,i check mysql data,i find mysql had added many records.i don't understand.
i just send an email..i think it only add two records to mysql (because mirror is enable)
and i did not receive any error infomation..but you said if use "oMessage.clearrecipients",i should be receive some error info like " No remaining recipients "
And then you told me i should add omessage.save
"or the message won't be saved after you clear the recipients, ie the message will still have all recipients"
the question:
because i did not add omessage.save, so ,as you said,the message will still have all recipients....it means all recipients can receive the mail
but actually,none recipient receive the mail..
i explain my question again
test:
Code: Select all
Sub OnDeliverMessage(oMessage)
call method1 'method1 is add one record to mysql (only add one record everytime)
oMessage.clearrecipients
End Sub
i just send an email..i think it only add two records to mysql (because mirror is enable)
and i did not receive any error infomation..but you said if use "oMessage.clearrecipients",i should be receive some error info like " No remaining recipients "
And then you told me i should add omessage.save
"or the message won't be saved after you clear the recipients, ie the message will still have all recipients"
the question:
because i did not add omessage.save, so ,as you said,the message will still have all recipients....it means all recipients can receive the mail
but actually,none recipient receive the mail..
Re: Local Send Only
if you script generated script error message may not be delivered. Did script generate errors? Check your logs
Re: Local Send Only
NO,i had checked the logs ,no any error info
and mail did not recevie any wrong msg
if i use the same code on method of "onacceptmssage",logs file have one wrong msg...
and mail did not recevie any wrong msg
if i use the same code on method of "onacceptmssage",logs file have one wrong msg...
Re: Local Send Only
Depends on where that is called.happylcg wrote:and i did not receive any error infomation..but you said if use "oMessage.clearrecipients",i should be receive some error info like " No remaining recipients "
From OnDeliverMessages, I'd say that you wouldn't get that error, as the message has already been delivered.
Again, same answer, depends on where it is being called.happylcg wrote:And then you told me i should add omessage.save
"or the message won't be saved after you clear the recipients, ie the message will still have all recipients"
And that was because you were saying that you were getting unending amount of these being triggered.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Local Send Only
thank you very much!!
I'm not sure exactly what you mean,but i still don't very clear.
and i found that how to stop mysql get endless msg.i need to disable mirror
the code and test result as bellow:
Test
fromaddress from@yahoo.com
recipient r@sameple.com
TEST1: enable mirror ,mirror address is backupm@sameple.com
mysql data shows the result like this (endless records)
row ...... ... sender..............................recipient ....................................... omessageid
1................. from@yahoo.com..................r@sameple.com...............................10067
2................. from@yahoo.com.................backupm@sameple.com......................10068
........................................................................................................
x................. from@yahoo.com..................backupm@sameple.com......................xxxxx
x................. from@yahoo.com..................backupm@sameple.com......................xxxxx
………………………………bellow all the same………………………………
TEST2.disable mirror
mysql data shows the result like this (just one record)
sender..............................recipient ....................................... omessageid
from@yahoo.com..................r@sameple.com...............................10067
so ,it is very clear ,mysql add endless record ,because i enable the mirror
but why ?
now i can avoid this problem by add one line "if oMessage.Recipients.Item(0).Address<>mirror@sameple.com"
but i still don't understand why if enable mirror it will like that ……
I'm not sure exactly what you mean,but i still don't very clear.
and i found that how to stop mysql get endless msg.i need to disable mirror
the code and test result as bellow:
Code: Select all
Sub OnDeliverMessage(oMessage)
call excute(sender,recipient,id) 'this method is add oMessage info to mysql
oMessage.clearrecipients
oMessage.save 'i find add this line or not ,the result is the same
End Sub
Test
fromaddress from@yahoo.com
recipient r@sameple.com
TEST1: enable mirror ,mirror address is backupm@sameple.com
mysql data shows the result like this (endless records)
row ...... ... sender..............................recipient ....................................... omessageid
1................. from@yahoo.com..................r@sameple.com...............................10067
2................. from@yahoo.com.................backupm@sameple.com......................10068
........................................................................................................
x................. from@yahoo.com..................backupm@sameple.com......................xxxxx
x................. from@yahoo.com..................backupm@sameple.com......................xxxxx
………………………………bellow all the same………………………………
TEST2.disable mirror
mysql data shows the result like this (just one record)
sender..............................recipient ....................................... omessageid
from@yahoo.com..................r@sameple.com...............................10067
so ,it is very clear ,mysql add endless record ,because i enable the mirror
but why ?
now i can avoid this problem by add one line "if oMessage.Recipients.Item(0).Address<>mirror@sameple.com"
but i still don't understand why if enable mirror it will like that ……
Re: Local Send Only
Tezcatlipoca wrote:***UPDATE*** Ah ha! I restarted hMail, made sure the script was there, Enabled and Reloaded then tried again and it looks like it's working fine!
My test user can currently email to @mydomain.com accounts, which is correct, but an email to my external gMail account still isn't as having as having arrived, which was sent about 10 minutes ago!![]()
mattg, you are an absolute star, sir!
I did initially want my users to get a message back saying that they couldn't email external accounts when they tried, but I'm guessing I can do this on a user by user basis via rules? Or is it fairly simple to add something to this script that says it?
What if you have 5 domain to check ? Say my.domain1, my.domain2.... etc ?
Re: Local Send Only
As local domains that are OK to send to each other??
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
-
- New user
- Posts: 2
- Joined: 2019-05-06 11:33
Re: Local Send Only
i have same problem pls help When restricted user send an e-mail, all 'CC/BCC' will changed to 'To'
Re: Local Send Only
Same answer appliessathya8561 wrote: ↑2019-05-06 11:41
i have same problem pls help When restricted user send an e-mail, all 'CC/BCC' will changed to 'To'
mattg wrote: ↑2013-01-09 10:27Sure,
You would need to get all recipients as it currently does, and also find out which of these recipients are TO and CC recipients, and when adding them back, add them back as they were previously.
All additional recipients should be BCC recipients.
Feel free to make the changes you need, and please post here if you need help and to post the results of your work so that others can use it.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
-
- New user
- Posts: 2
- Joined: 2019-05-06 11:33
Re: Local Send Only
bro sorry i didn't get what you said i humbly request you kindly explain clearly is there any script pls guid me