Configuring hmailserver for university mailing system

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
Post Reply
farooqbassam
New user
New user
Posts: 3
Joined: 2015-10-12 23:29

Configuring hmailserver for university mailing system

Post by farooqbassam » 2015-10-12 23:50

Hi,
so i've set up hmail server and wamp on my system.
Did setup my database using wamp's built in mysql db system.
what i want to do is:
setting the mail server so that i mail the id configured on my hmailserver and in turn it sends that email to every students and teachers email ids in the database.
i am not sure if i put it correctly or not but any help or leads would be appreciated.
Thanks !! :)

User avatar
jimimaseye
Moderator
Moderator
Posts: 8302
Joined: 2011-09-08 17:48

Re: Configuring hmailserver for university mailing system

Post by jimimaseye » 2015-10-12 23:56

Set up a distribution list containing all the addresses you want it to include, then send your email to that list. OR have a script that checks for your incoming message and sends it out as a SERVER MESSAGE using the ServerMessage object (if you think this is suitable). https://www.hmailserver.com/documentati ... vermessage
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

farooqbassam
New user
New user
Posts: 3
Joined: 2015-10-12 23:29

Re: Configuring hmailserver for university mailing system

Post by farooqbassam » 2015-10-13 11:34

thanks jimimaseye
the first option is not feasible because maintaining a distribution list of 20000+ students is not the best option as i have to categorise them as per the departments.
Though the second option is better but i didn't really get ho to do it.
Can you explain further?

User avatar
jimimaseye
Moderator
Moderator
Posts: 8302
Joined: 2011-09-08 17:48

Re: Configuring hmailserver for university mailing system

Post by jimimaseye » 2015-10-13 11:54

You say you cant manage the distribution list as you have to categorise them first. This suggests to me that not all email addresses are eligible for the list and therefore some qualify and some dont. If this is the case, then neither options will suffice as the sending out a SERVER MESSAGE will send to everyone irrespective of whatever category you consider them to belong in.

So either:

a, its ALL or NOTHING regarding email addresses - this can be done with scripting to send a SERVER MESSAGE to ALL emails
  • OR
b, you need to be selective of addresses in which case scripting to send SERVER MESSAGES will not be any use. But you can use scripting to import a or maintain a distribution list based on an import file (perhaps generated from a spreadsheet you have used to filter and categorize the email addresses that qualify)

Your answer does lie in scripting and you will be able to have a solution:

a> if incoming (specially crafted) email contains subject "send out server message" and is from "admin"
then
run function "SendMessage"

where "SendMessage" is your script to send out a server message https://www.hmailserver.com/documentati ... vermessage


b> Script reads an import file containing addresses and creates a distribution list with its contents. https://www.hmailserver.com/documentati ... butionlist
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

tochi
Senior user
Senior user
Posts: 278
Joined: 2015-07-28 22:55

Re: Configuring hmailserver for university mailing system

Post by tochi » 2015-10-13 23:08

You should have student, department tables in database (mySql, SQL Server, Oracel whatever) already.
I would setup synchronization mechanism from your campus database to hmailserver. You can define your distribution lists by class, by department or whatever you want. It should be customized coding which reads data from your campus database and push that to hmailserver through hmailserver COM API or inserting/updating tables directly (less prefered).
Once it's in place, you can simply send only one email to the selected distribution list and hmailserver will do the rest.

farooqbassam
New user
New user
Posts: 3
Joined: 2015-10-12 23:29

Re: Configuring hmailserver for university mailing system

Post by farooqbassam » 2015-10-14 14:52

ok so i consulted with my mentor.
heres the scenario.
he asked to reconsult you.
we have an email server already setup.
what we want to do is with a domain say xyz.com and email abc@xyz.com
So when we send and email from say abcd@gmail.com to abc@xyz.com its forwards that email to all the email ids on the server database. And we want the process to be automated.
if you can help me with the script for that it'll be very helpful.

User avatar
jimimaseye
Moderator
Moderator
Posts: 8302
Joined: 2011-09-08 17:48

Re: Configuring hmailserver for university mailing system

Post by jimimaseye » 2015-10-14 15:02

Yes, this is exactly what I had in mind on my first answers. The specially crafted email is received, and subsequently forwarded to all 'enabled' email addresses that exist in the domain.

eg,
Email received to "broadcast@domain1.com"

RULE:
if RECIPIENT is "broadcast@" then run function "SendBroadcastEmail"

Function "SendBroadCastEmail"

For all email addresses at domain "domain1.com" do
add recipient : the current email address of FOR loop to the email received
End For
Save Message

It is a simple enough script. I personally am not a scriptor but if I find time I will try to knock something up to give you a start (but PLEASE dont rely on me doing this for you).
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

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

Re: Configuring hmailserver for university mailing system

Post by SorenR » 2015-10-14 15:49

Hint...

Code: Select all

Function EmailAllAccounts(ByVal sRecipientWildcard As String, 
                          ByVal sFromAddress As String, 
                          ByVal sFromName As String, 
                          ByVal sSubject As String, 
                          ByVal sBody As String) As Boolean

    Member of hMailServer.Utilities
    Sends an email message to accounts on the server.

Dim sRecipientWildcard
sRecipientWildcard = "*@domain.com"
-or-
sRecipientWildcard = "john*@domain.com"
-or-
sRecipientWildcard = "*doe@domain.com"

Call oApp.Utilities.EmailAllAccounts(........
-or-
If oApp.Utilities.EmailAllAccounts(........) = false Then
   ECHO FAIL !!!
End If
My guests have just arrived, so I'm checking out for today - Happy b-day to me :mrgreen:
SørenR.

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

User avatar
jimimaseye
Moderator
Moderator
Posts: 8302
Joined: 2011-09-08 17:48

Re: Configuring hmailserver for university mailing system

Post by jimimaseye » 2015-10-14 15:52

try this:

1, put it in to the eventhandlers script.
2, Create a secret user for each domain called "serversendout@..."
3, When you need a server sendout, send a message FROM "serversendout@domainchoice.com" to: "serversendout@domainchoice.com"

ie, ensure the FROM and TO are the same and that the TO ONLY contains that single address (effectively sending it to itself).

4, The script sees and identifies that and will cycle through and add all valid email addresses found in the domain of the email "domainchoice.com" and will deliver the email that was initially sent to them (whilst removing the original secret "serversendout@" address and replacing the FROM with DONOTREPLY.

5, Copy the code in to the bottom EVENTHANDLERS.VBS and then create a global rule that triggers it
eg, RULE:
  • if FROM contains 'serversendout' THEN Run Function "ServerSendOut".
Alternatively you may make the function permanent without the need of calling by a rule by copying the code WITHOUT the opening and closing "Sub" lines in to the "OnAcceptMessage" sub routine within Eventhandlers.vbs (where it will always run and check for the conditions coded within it.)

WARNING!!! AT OWN RISK Dont beef at me if it gets misused and/or you fail to test to your requirements first.

Code: Select all

Sub ServerSendOut(oMessage)
      Dim y, aUsername, oApp, oDomain, Countit, Found
      BatchLimit = 20
      Found = 0
      Set oApp = CreateObject("hMailServer.Application")
      Call oApp.Authenticate("Administrator", "secretpassword" )
      aUsername = Split(oMessage.fromaddress,"@")
      If lcase(aUsername(0)) = "serversendout" then
         If oMessage.Recipients.count = 1 then
            If lcase(oMessage.Recipients(0).Address) = "serversendout@" & aUsername(1) then
               Set oDomain = oApp.Domains.ItemByName(aUsername(1))
               Countit = 0
               For y = 0 To oDomain.Accounts.Count - 1
                  Set oAccount = oDomain.Accounts.Item(y)
                  If oAccount.Active Then
                     If lcase(oAccount.address) <> lcase(oMessage.fromaddress) then
                        If Found = 0 then
                           If Countit = BatchLimit Then
                              Countit = 0
                              Found = 1
                           Else
                              If Countit = 0 then
                                 oMessage.ClearRecipients()
                                 oMessage.From = "Admin <donotreply@" & aUsername(1) &">"
                              End If
                              oMessage.AddRecipient oAccount.address, oAccount.address
                              Countit = Countit + 1
                           End If
                        End If
                        If Found = 1 then
                           If Countit = BatchLimit Then
                              newMessage.Save
                              Countit = 0
                           End If
                           If Countit = 0 then
                              Set newMessage = CreateObject("hMailServer.Message")
                               newMessage.From = "Admin <donotreply@" & aUsername(1) &">"
                               newMessage.Subject = oMessage.Subject
                               newMessage.Body = oMessage.Body
                               newMessage.HTMLBody = oMessage.HTMLBody
                               newMessage.Date = oMessage.Date
                               newMessage.ClearRecipients()
                           End If
                           newMessage.AddRecipient oAccount.address, oAccount.address
                           Countit = Countit + 1
                        End If
                     End If
                  End If
               Next
               If Found = 0 and Countit = 0 then
                  oMessage.subject = "Serversendout message REJECTED. No users for this domain where found active."
               End If
               oMessage.Save
               newMessage.Save
            End If
         Else
            oMessage.ClearRecipients()
            oMessage.AddRecipient "serversendout@" & aUsername(1) , "serversendout@" & aUsername(1)
            oMessage.subject = "Serversendout message REJECTED. Send only to the user serversendout@ and no one else."
            oMessage.save
         End If
      End If
End Sub

If you add multiple recipients and fail to send TO 'Serversendout@' only it will return the email to the Serversendout Inbox informing you and no other delivery will be done. Similarly, an email will be returned if no active users in the domain are found.

The purpose of sending from secret user "Serversendout@domain.com" instead of just from any account (such as fred@gmail.com) stops unauthorised senders of emails (theory being only you/admin know the email address to use and the password to authenticate it for double security to stop funny jokes and pictures of the University Head Professor in his underpants being broadcast). :lol:

The script also breaks up the list addresses in to batches of 20 (as set the variable "BatchLimit" - modify to choice) and sends one email per batch to prevent trying to add hundreds or thousands of users to a single email.

This script allows for individual targeting where the server might be hosting multiple domains and have different interests. It is limited to that of a SERVER MESSAGE (which has the ability to choose ALL, DOMAIN or user by wildcard pattern) BUT this offers the ability to retain and forward a formatted email from a client rather than a more limited plain text email from the Server Message feature. And anyway, *I* dont know how to script and so have no idea how to have done it with the ServerMessage feature. :roll:
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
jimimaseye
Moderator
Moderator
Posts: 8302
Joined: 2011-09-08 17:48

Re: Configuring hmailserver for university mailing system

Post by jimimaseye » 2015-10-14 19:11

SorenR wrote: My guests have just arrived, so I'm checking out for today - Happy b-day to me :mrgreen:
Tillykke med fødselsdagen!
Image
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

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

Re: Configuring hmailserver for university mailing system

Post by SorenR » 2015-10-15 00:44

jimimaseye wrote:
SorenR wrote: My guests have just arrived, so I'm checking out for today - Happy b-day to me :mrgreen:
Tillykke med fødselsdagen!
Thanks mate :mrgreen:
SørenR.

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

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

Re: Configuring hmailserver for university mailing system

Post by mattg » 2015-10-15 02:44

Happy birthday from me too...
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: 3316
Joined: 2006-08-21 15:38
Location: Denmark

Re: Configuring hmailserver for university mailing system

Post by SorenR » 2015-10-15 14:41

mattg wrote:Happy birthday from me too...
Thanks mate :mrgreen:
SørenR.

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

User avatar
jimimaseye
Moderator
Moderator
Posts: 8302
Joined: 2011-09-08 17:48

Re: Configuring hmailserver for university mailing system

Post by jimimaseye » 2015-10-15 22:10

Script above was updated with slight reworkings to return email back to user 'serversendout@' if no users where found active for the domain specified.

@farooqbassam (the OP)
At least an acknowledgement of reading this would be appreciated - this effort wasnt for anyone else.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

Post Reply