Create a dynamic list and send to from an address

This section contains scripts that hMailServer has contributed with. hMailServer 4 is needed to use these.
Post Reply
spydersweb
New user
New user
Posts: 5
Joined: 2007-07-27 17:02

Create a dynamic list and send to from an address

Post by spydersweb » 2007-10-01 18:14

I have a site that sends an email to every member in a database that currently sends a notification when a new notice is posted on the website. With so many members some 650 or so, it is getting to the stage that sending using an ASP script is not viable. I am starting to get time out errors, and whilst I think to extend the script time out is a bit of a cop out, I would much prefer to script a solution that draws each recipient from the database as soon as a message is sent to a specific address. I can then let HMail handle the send out rather that looping through each member of the database.

Does anybody know where i can get some ideas on how to script this or has somebody done this before. I am not new to VbScript but I am to using Hmail and so any help is greatly appreciated.

many thanks
Graham

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-10-01 18:26

I do not think this is an ASP problem. Are you using a virus scanner such as clamwin?

I used to struggle sending around 1000 mails with php when i had AV enabled. As soon as I switched to a dedicated outgoing mail server with no AV on it I can pump upto around 15,000 emails into hmail without breaking a sweat.

spydersweb
New user
New user
Posts: 5
Joined: 2007-07-27 17:02

Create a dynamic list and send to from an address

Post by spydersweb » 2007-10-01 18:31

I am using Clamwin, but have already had it load tested and been told that it is running fine. Not that I understand the finer points of setting up Hmail. It was running slow, but that was down to Clamwin as rightly said. However this was updated and checked and now it seems to run ok.

However I select all the recipients from the database as a recordset and then loop through each of them and send out the email to each email address in the recordset.

In your setup you have two seperate servers(computers) or two seperate versions of Hmail running. One to handle incoming and the other to handle outgoing emails?

thanks for the prompt response.

Graham

spydersweb
New user
New user
Posts: 5
Joined: 2007-07-27 17:02

Post by spydersweb » 2007-10-01 18:34

spydersweb wrote:I am using Clamwin, but have already had it load tested and been told that it is running fine. Not that I understand the finer points of setting up Hmail. It was running slow, but that was down to Clamwin as rightly said. However this was updated and checked and now it seems to run ok.

However I select all the recipients from the database as a recordset and then loop through each of them and send out the email to each email address in the recordset.

In your setup you have two seperate servers(computers) or two seperate versions of Hmail running. One to handle incoming and the other to handle outgoing emails?

thanks for the prompt response.

Graham
sorry I dont think I am making any sense.

The script I have running loops through a recordset and sends an email to each email address in the list. Do you know of a better way to perform this task?

In your setup do you have two separate computers or two separate versions of Hmail running?

Sorry for not being clear.
Graham

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-10-01 19:10

Hi Graham,

I have a main server that handles all normal incoming and outgoing emails but as I found out my system would get clogged up due to AV scanning and the mass amounts of emails in hmails queue which delayed normal emails so I Installed a second copy of hmail on another server on my network which purely sends email out and directed all server generated email to use the other machine on my network.

This worked out great for me and I send out email in much the same manner as you although I do not know ASP I use PHP and MySQL, I wrote a script that pulls back everyone i need from my database and I just loop through the object returned, generate a personalised email and send it to hmails queue.

As I mentioned before I disabled clamwin when I had problems with script timeouts but when I disabled AV (At the time i was using clamwin and before I moved to a dedicated outgoing server setup ) I had no problems pumping thousands of emails into hmail. There were 2 reasons I switched to a dedicated outgoing server. The first was hMail did not have the ability to disable AV for outgoing email (I believe V5 will have this ability though) and second all the emails in hmails queue were holding up legitimate emails going out from my users.

I suggest you just give your script a try without clamwin enabled to see if it makes any difference or not.

Cheers!

toetag_hmail
Normal user
Normal user
Posts: 119
Joined: 2007-06-25 16:55
Location: Nowhere, USA

Re: Create a dynamic list and send to from an address

Post by toetag_hmail » 2007-10-01 21:57

spydersweb wrote:Does anybody know where i can get some ideas on how to script this or has somebody done this before. I am not new to VbScript but I am to using Hmail and so any help is greatly appreciated.
if you can get the VBScript to get the email addresses and preset the body, here is a function i've used to actually send the email:

Code: Select all

SUB SendMessage(toaddress,todisplayname,fromname,fromaddress,subject,messagebdy, attachment)
   dim oMessage
   Set oMessage = CreateObject("hMailServer.Message")
   With oMessage   
   	.From = fromname & " <"& fromaddress & ">"
   	.FromAddress = fromaddress
   	.Subject = subject
   	.AddRecipient todisplayname, toaddress
   	.Body = messagebdy
	.Attachments.Add attachment
   	.Save
   	End With 
   	Set oMessage = Nothing 
END Sub 
note: you can remove the references to the "attachment" if you wont be needing attachments. this assumes you have the hMail API running on the machine you'd use the script on.
a desert to an Irishman is an empty glass.

spydersweb
New user
New user
Posts: 5
Joined: 2007-07-27 17:02

Post by spydersweb » 2007-10-01 23:40

toetag_hmail wrote:
spydersweb wrote:Does anybody know where i can get some ideas on how to script this or has somebody done this before. I am not new to VbScript but I am to using Hmail and so any help is greatly appreciated.
if you can get the VBScript to get the email addresses and preset the body, here is a function i've used to actually send the email:

Code: Select all

SUB SendMessage(toaddress,todisplayname,fromname,fromaddress,subject,messagebdy, attachment)
   dim oMessage
   Set oMessage = CreateObject("hMailServer.Message")
   With oMessage   
   	.From = fromname & " <"& fromaddress & ">"
   	.FromAddress = fromaddress
   	.Subject = subject
   	.AddRecipient todisplayname, toaddress
   	.Body = messagebdy
	.Attachments.Add attachment
   	.Save
   	End With 
   	Set oMessage = Nothing 
END Sub 
note: you can remove the references to the "attachment" if you wont be needing attachments. this assumes you have the hMail API running on the machine you'd use the script on.
thanks doom for explaining your setup to me. I will certainly give it a try.

toetag_hmail thanks for the script:

I am guessing that I can create a recordset object and then use your script to loop through the recordset and send an email to each recipient. Am I right in saying that I can trigger this using a rule, and send a dummy message to an email account to activate the rule?

Not sure if I am actually getting it, however the message needs to say the same thing to everybody, apart from it will need to be personalised. So I can substitute the ASP script that I am currently using and instead just send one message to a dummy email account, which is simply waiting to do a bulk email send. I then have this rule setup on the server that will call this script that then creates the recordset and loops through each recipient?

Many thanks
Graham

toetag_hmail
Normal user
Normal user
Posts: 119
Joined: 2007-06-25 16:55
Location: Nowhere, USA

Post by toetag_hmail » 2007-10-02 06:45

spydersweb wrote: I am guessing that I can create a recordset object and then use your script to loop through the recordset and send an email to each recipient. Am I right in saying that I can trigger this using a rule, and send a dummy message to an email account to activate the rule?

I'm shooting from the hip on this one but you could use a trigger and send an email out based on the email you send to "trigger" the trigger.

Code: Select all

Sub Newsletter(oMessage)
	if oMessage.Subject = "@SendEmail - Some Subject" then
        ...
	end if
End Sub
Use the above to detect a specific subject(i used "@SendEmail - Some Subject"). Then in this function, call your script that gets the recordset with all your email address. Then loop through this recordset to send the email. in the loop, you can pass oMessage.Body from the original email to the SendMessage. Trim the oMessage.Subject from "@SendEmail - Some Subject" so it's just "Some Subject" and pass this to the SendMessage as well.

a little messy, but possible. Could clean it up and allow for some subject parsing to do different things. Also, a little unsecure as anyone that knew your special "Subject" to call the function could easily send out emails without your consent.
a desert to an Irishman is an empty glass.

Post Reply