Forum Moderators: open

Message Too Old, No Replies

ASP mail script question

         

grnidone

9:54 pm on Jul 13, 2001 (gmt 0)



I have a simple mail script for a Windows 2000 box.

All I need to do is have the mail form send to more than one address. How do I list more than one mail server and more than one address?

Script follows
--------------------------------

<%Set mailer = Server.CreateObject("ASPMAIL.ASPMailCtrl.1")
recipient = "name@whatever.com"
sender = Request.Form("First")
subject = "Form email here"
message = message & "TEXT BOX NAME OF FORM 1" & Request.Form("ONE")&chr(10)&chr(13)
message = message & "TEXT BOX NAME OF FORM 2 " & Request.Form("TWO")&chr(10)&chr(13)
message = message & "TEXT BOX NAME OF FORM 3" & Request.Form("THREE")&chr(10)&chr(13)
message = message & "TEXT BOX NAME OF FORM 4" & Request.Form("FOUR")&chr(10)&chr(13)
message = message & "TEXT BOX NAME OF FORM 5" & Request.Form("FIVE")&(",")&Request.Form("SIX")&chr(10)&chr(13)
message = message & "Comment / Question: " & Request.Form("MESSAGE OF FORM")&chr(10)&chr(13)
message = message &chr(10)&chr(13)
message = message &chr(10)&chr(13)
mailserver = "mail.whatever.com"
result = mailer.SendMail(mailserver, recipient, sender, subject, message)
%>
<% If "" = result Then %>
<%=Request.Form("NAME")%><p><font size="2" face="Arial">
GENERIC THANK YOU MESSAGE HERE</font></p>
<% Else %><font face="Arial" size="2"> </font>
<font face="Arial" size="2">Your e-mail was not sent.
Please e-mail us directly, at
email@whatever.com.
Error message: <%= result %>
  </font>
<p> </p>
<p> </p>
<p>
<% End If %> 

-G
PS (I know *nothing* about ASP, so if you could point me to some good resources, I'd appreciate that too.)

shakes911

9:12 am on Jul 19, 2001 (gmt 0)



if you put the email addresses into a text file and then used an until atendofstream loop and CDONTS to read the mail addresses from the text file and send them, i think that would work. the script would be something like this:

<%
sender = "joe@company.com" 'could be extracted from a form
subj = "email subject" 'could be extracted from a form
bod = "generic body of email" 'could be extracted from a form
footer = "generic ending to email" 'could be extracted from a form
Dim fname(5000), sname(5000), uname(5000), agency(5000), pass(5000)
Dim regsys, userfile
Set regsys = CreateObject("Scripting.FileSystemObject")
varUserfile = Server.MapPath("emaillist.txt")
Set userfile = regsys.OpenTextFile(varUserfile,1)
Do While Not userfile.AtEndOfStream
data = userfile.ReadLine
'if you wish to include the recipients name as well as their email address use a symbol to seperate the date, in this case: $#. if you only wish to include the address, the next 3 lines are unnecessary
temp = Split(data,"$#")
recipadd = temp(0) 'assuming that the email address is first, and the name second in the text file
recipname = temp(1)
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "host.host.host" ' Specify a valid SMTP server
Mail.From = sender
Mail.AddAddress recipadd, recipname
Mail.Subject = subj
Mail.Body = bod & Chr(13) & Chr(13) & footer
Mail.Send
On Error Resume Next
Mail.SendToQueue
Set Mail = Nothing
Loop
userfile.close
%>

the text file would look something like this:

joe.smith@email.com$#Joe Smith
jammydodger@email.com$#Bill Hudson
rosy@email.net$#Rose Arden

hope this helps

Xoc

5:10 pm on Jul 21, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That script won't work right. Because of the hard-coded filename, if you have two people hit the page at the same time, they will conflict. Writing files with Scripting.FileSystemObject is not a good solution for scalable web sites.

You can simply use a semi-colon separated list of email addresses to send to, and it will take care of it. The CDONTS send command is described here: [msdn.microsoft.com ]

I originally posted the basic form for the CDONTS send command here: [webmasterworld.com ]

grnidone

8:42 pm on Jul 21, 2001 (gmt 0)



Xoc,

I am confused. When you say "that script won't work", which script are you referring to?

Then, do I use the semi colon separated list with the first script or the second?

-G

Xoc

11:23 pm on Jul 21, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was referring to shakes911's script. Because it creates a file, then reads from the file, if two or more people hit the web page at the same time, they both try creating the same file. So only one of them will "win", and the others all "lose".

To send mail use this:


Dim cdonts
Set cdonts = Server.CreateObject("CDONTS.NewMail")
Call cdonts.Send("from@domain.com","to1@domain1.com;to2@domain2.com;to3@domain3.com", "this is a subject", "this is a body", 1)
Set cdonts = Nothing

I'll send you a complete example of an email form by sticky.