Click to See Complete Forum and Search --> : mass e mail


yaniv hanya
01-03-2004, 01:18 PM
i use jmail object and this code to send e mail to all my visitors.

response.write "משלוח לכל המתמשים הרשומים באתר:<BR><BR>"

OpenConnection
sql="SELECT DISTINCT email FROM tbl_Users"
rst.open sql

do while not rst.EOF
set msg = Server.CreateOBject( "JMail.Message" )
msg.Logging = true
msg.silent = true
msg.AddRecipient rst("email")
msg.From = "shoresh@shoresh.org.il"
msg.FromName = "אתר שורש"
msg.Subject = request("subject")
msg.Charset = "windows-1255"
' msg.AppendHTML ("<body dir=rtl><div align=center><table width=600><tr><td><BR><a href = "http://www.shoresh.org.il/"><div align=center><img src='http://www.shoresh.org.il/Images/menu2/logo.jpg' width=428 height=38></div></a><BR><BR><BR>")
msg.AppendHTML ("<font face='tahoma' size=2>" & "<a href = 'http://www.shoresh.org.il/'>לכניסה לאתר לאתר שורש- לחצו כאן</a>" & vbcrlf & "<BR>")
msg.AppendHTML ("<font face='tahoma' size=2>" & replace(request("text"),vbcrlf,"<BR>"))
if not msg.Send( "smtp.012.net.il" ) then
Response.write "<span class='bred'>כתובת אימייל בעייתית</span> --> "
end if
set msg = nothing

response.write i & ". " & rst("email") & "<BR>"
i=i+1
rst.MoveNext
loop

i=i-1
rst.close
CloseConnection

end if


the problem is the the machine stuck when i try to send e mail to every one (the first ones get the full mail, after it just the first line, and the it is stuck).

PeOfEo
01-04-2004, 08:50 PM
Yes it is going to lag up, try slowing it down a bit, make it do something between seding mail to the smtp, put it on a loop or something and do something else in the mean time.

yaniv hanya
01-05-2004, 04:22 PM
does response.write is something to do?


i mean. i can't go out the loop, and them get in again!

PeOfEo
01-05-2004, 04:48 PM
You can leave a loop and go in as many times as you want by just calling the sub again :p. What would be the problem? response.write just prints a <span> of text at the top of your page.

CardboardHammer
01-05-2004, 06:11 PM
For any interested person with ASP.NET available...

(Code modified to strip it of things that might identify me/my employer (I almost left my e-mail address in there :eek: ). It should be usable, given obvious changes to suit a user's needs.)

Module1.vb


Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Mail
Module Module1
Sub Mailshot()
Dim conXXX As New SqlConnection("Data Source=(local);Net=dbnmpntw;Database=XXX;")
Dim cmdXXX As New SqlCommand("GET_XXX", conXXX)
cmdXXX.CommandType = CommandType.StoredProcedure

Dim msgmail As MailMessage = New MailMessage()
SmtpMail.SmtpServer = "XXX.XXX.XXX.XXX"
msgmail.From = "XXX@XXX.XXX"

Dim rdrXXX As SqlDataReader
conXXX.Open()
rdrXXX = cmdEOC.ExecuteReader(CommandBehavior.SequentialAccess)
While rdrXXX.Read()
Try
msgmail.To = rdrXXX.GetString(0)
msgmail.Body = "STUFF..."
msgmail.Subject = "SUBJECT..."
msgmail.BodyFormat = MailFormat.Html
SmtpMail.Send(msgmail)
Catch exc As Exception
'DO WHATEVER ERROR HANDLING
End Try
End While

rdrXXX.Close()
rdrXXX = Nothing
cmdXXX.Dispose()
cmdXXX = Nothing
conXXX.Close()
conXXX.Dispose()
conXXX = Nothing
msgmail = Nothing
End Sub
End Module


I use a version that the above code was derived from as an exe, but the above should work (with edits that suit the user's details) when called withing an ASP.NET page.

PeOfEo
01-05-2004, 06:26 PM
asp.net is just regular vb6 which has been modified with a few new keywords and some sql so it should work, I have used exe code too :D. But that is doing what I said, using a loop and sending the emails in that. You can take it one step further by looping through an array.

CardboardHammer
01-05-2004, 06:52 PM
Originally posted by PeOfEo
asp.net is just regular vb6 which has been modified with a few new keywords and some sql ...

Umm... You're really selling it short... VB.NET looks similar to VB6, but it's much, much better.

PeOfEo
01-05-2004, 08:25 PM
I have not used much with asp.net in vb that I have not done in vb6 syntax wise. I mean its all the same, you have all of the same structures like if else, while loop, case, try catch, etc. There is not much more language wise besides keywords from what I have seen. The whole response.redirect request.server variables so on and so fourth, all of that is new but that is because it is running on the internet and not on a pc as an exe. Please fill me in on what is new to the language besides some new keywords and maybe a few new elements that are .net pimped out for conveiniance.

CardboardHammer
01-05-2004, 08:37 PM
Real OO (not half-assed, like in VB6) and exceptions (no more "on error goto hell" BS... this is a VERY good thing), for starters.

PeOfEo
01-05-2004, 09:26 PM
well yea its oo, but besides being able to use classes and all what are the language syntax differences, because I have not seen any.

CardboardHammer
01-05-2004, 11:12 PM
try/catch wasn't in VB6.

yaniv hanya
01-06-2004, 01:23 AM
thanks, every body.

I use both .net and asp so it is realy helpfull.

Calmaris
01-06-2004, 01:28 AM
Have you figured it out? I have some code for mass emailing that references emails in a database. It's really short code as well and simple...lol even for me.

yaniv hanya
01-06-2004, 02:21 AM
please send the code, it will be usefull.

what i got is that i should build a sub of the send action and then call it time after time from the loop.

Calmaris
01-06-2004, 02:28 AM
This is the actual web page with the text boxes for subject and msg body. I would pick through the code for you but I don't know exactly what you will need or what else may help. But It works great with no problem...this is classic ASP if your using ASP.NET you will have to modify it..I'm switched to ASP.NET so I'll be modifying it within the next few days let me know if you have any trouble.


<% @Language = VBScript %>
<% Option Explicit %>

<%
Dim strSubject, strTHE_BODY, SSQL, recordsetDB,ObjMail,Temp
Dim Hunt_Email, Hunt_First_Name, thebody, vbclf, dbConn
%>
<form method="POST" action="Admin_Email.asp">

<head>
<title></title>
</head>

<body background="grback.jpg">

<p>THE SUBJECT</p>

<p><input type="text" name="Subject" VALUE = "<%=strSubject%>" size="48"></p>

<p>THE BODY</p>

<p><textarea rows="8" name="THE_BODY" VALUE = "<%=strTHE_BODY%>" cols="52"></textarea></p>
<p><input type="submit" value="Submit" name="B1"></p>

</form>
<%
Set dbConn = Server.CreateObject("ADODB.Connection")

dbConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=somewhere/Hunting.mdb")

%>

<%'--------------------request the form elements and write to variables----------------------

Temp=request.form("Subject")
If Temp <> "" then
SSQL= "SELECT * FROM Hunt_Registration"
Set recordsetDB = dbConn.Execute(SSQL)

recordsetDB.MoveFirst

While Not recordsetDB.EOF

Hunt_Email = recordsetDB.Fields("Hunt_Email").value
Hunt_First_Name = recordsetDB.Fields("Hunt_First_Name").value

StrSubject = request.Form("Subject")
strTHE_BODY = request.Form("THE_BODY")


'-------------------setup the CDONTS email object-------------------------------------
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
'------------------------Set the email elements------------------------------
ObjMail.To = ""& Hunt_Email &""
ObjMail.CC = ""& Hunt_Email &""
ObjMail.From = "me@you.com"
ObjMail.Subject = ""& Replace(StrSubject,"'","'") &""
thebody = ""& Replace (strTHE_BODY,"'","''") &"" & vbcrlf
'----------------create the body of the message------------------------
ObjMail.Body = "Hello "& Hunt_First_Name &" "& strTHE_BODY & ""
'----------------------send the message-----------------------------------
ObjMail.Send
Set ObjMail = Nothing

'---------------------insert the information into the database------------------------
recordsetDB.MoveNext

Wend
end if

%>
<p><a href="Admin.asp">Back To Admin Page</a></p>