Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SMTP Emailing

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I am new to ASP and need to send an email when the page is submitted. basically what I want to do is have an email sent to a user who's email address is stored in the database. The email will have a link which will open a record based an a UserID field in the database and month. Can someone tell me the best way to do this, or point me to a tutorial on how to do this?
 
Depending on what you have installed on your web server, you may be able to use NTDONTS.DLL. There are security issues related to this dll, and depending on what you have installed, you may or may not be able to use it. There are many third party products you can use to simplify sending email from ASP. Typical code looks like this:

Dim oMail
Set oMail = Server.CreateObject("Persists.MailSender")

oMail.IsHTML = True
oMail.Host = "exchange.domain.com.au"
oMail.AddAddress = "whoitsto@mail.com"
oMail.From = "whoitsfrom@mail.com"
oMail.Subject = "My Subject"
oMail.Body = &quot;<a href='test.asp'>link you wanted</a>&quot;
oMail.Send

Set oMail = Nothing

As you can see, if you can find a third party product, or use NTDONTS.DLL, the process is quite simple.

I recommend ASPEmail by Persists Software as a third party product and you can find the download and demos at

Good Luck! Brett Birkett B.Comp
Systems Analyst
 
Sorry.. I meant CDONTS.DLL not NTDONTS.DLL Brett Birkett B.Comp
Systems Analyst
 
I am trying to do the same thing. I've taken over a site and the code was already created, but it doesn't seem to work. The form should be pulling the addresses from a access database. It seems to know who to send the form to, but nothing is ever received. If you ever figure it out I'd love to know how. Here is the code I have

<% page = &quot;Communication&quot; %>


<!-- #INCLUDE FILE=&quot;Includes/CheckUser.asp&quot; -->

<!-- #INCLUDE FILE=&quot;Includes/Header.asp&quot; -->

<!-- #INCLUDE FILE=&quot;Includes/menu.asp&quot; -->

<!-- #INCLUDE FILE=&quot;Includes/dbcon.asp&quot; -->


<%
SUB sendMail(fromWho, toWho, Subject, Body)
strEmails = &quot;&quot;

If Instr(toWho, &quot;Members&quot;) Then
Set RSMembers=Server.CreateObject(&quot;ADODB.RecordSet&quot;)
strSQL = &quot;SELECT * FROM Members WHERE Len(Email) <> 0 ORDER BY Email&quot;
RSMembers.Open strSQL, Con

Do While Not RSMembers.EOF
strEmails = strEmails & RSMembers(&quot;Email&quot;) & &quot;,&quot;
RSMembers.MoveNext
Loop

RSMembers.Close
Set RSMembers = Nothing
End If
If Instr(toWho, &quot;Officers&quot;) Then
Set RSOfficers=Server.CreateObject(&quot;ADODB.RecordSet&quot;)
strSQL = &quot;SELECT * FROM Officers WHERE Len(Email) <> 0 and Officer = True ORDER BY Email&quot;
RSOfficers.Open strSQL, Con

Do While Not RSOfficers.EOF
strEmails = strEmails & RSOfficers(&quot;Email&quot;) & &quot;,&quot;
RSOfficers.MoveNext
Loop

RSOfficers.Close
Set RSOfficers = Nothing
End If
If Instr(toWho, &quot;Directors&quot;) Then
Set RSDirectors=Server.CreateObject(&quot;ADODB.RecordSet&quot;)
strSQL = &quot;SELECT * FROM Officers WHERE Len(Email) <> 0 and Officer = False ORDER BY Email&quot;
RSDirectors.Open strSQL, Con

Do While Not RSDirectors.EOF
strEmails = strEmails & RSDirectors(&quot;Email&quot;) & &quot;,&quot;
RSDirectors.MoveNext
Loop

RSDirectors.Close
Set RSDirectors = Nothing
End If

'get rid of the last comma in the string
strEmails = Left(strEmails, len(strEmails) - 1)

'Code used to debug, to see all email addresses
intStart=1
intEnd=1
Do While Instr(intStart, strEmails, &quot;,&quot;)
intEnd=Instr(intStart, strEmails, &quot;,&quot;)
Temp=Mid(strEmails, intStart, intEnd - intStart)
intStart=intEnd + 1
Response.Write Temp & &quot;<BR>&quot;
Loop

'Send the Email to all parties
Dim myMail
Set myMail = Server.CreateObject(&quot;CDONTS.Newmail&quot;)
myMail.From = fromWho
myMail.To = toWho
myMail.Subject = Subject
myMail.Body = Body
myMail.Send
SET myMail = nothing
END SUB

fromWho = TRIM(Request.Form(&quot;fromWho&quot;))
toWho = TRIM(Request.Form(&quot;toWho&quot;))
Subject = TRIM(Request.Form(&quot;Subject&quot;))
Body = TRIM(Request.Form(&quot;Body&quot;))

IF toWho <> &quot;&quot; THEN
sendMail fromWho, toWho, Subject, Body
END IF
%>

<!-- Page Content -->
<TD ALIGN=&quot;LEFT&quot; VALIGN=&quot;TOP&quot; WIDTH=&quot;505&quot;>
<TABLE BORDER=&quot;0&quot; CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot; WIDTH=&quot;100%&quot;>
<% If Len(Request.Form(&quot;Submit&quot;)) Then %>
<TR>
<TD colspan=&quot;2&quot; VALIGN=&quot;TOP&quot; align=&quot;center&quot;>
<FONT SIZE=&quot;5&quot;><STRONG>Your message has been sent!</STRONG></FONT><P>
</TD>
</TR>
<% End If %>
<TR>
<TD colspan=&quot;2&quot; VALIGN=&quot;TOP&quot; align=&quot;center&quot;>
<DIV CLASS=&quot;Title&quot;>Communication Center</DIV>
</TD>
</TR>
<TR>
<TD valign=&quot;top&quot; ALIGN=&quot;CENTER&quot;>
<BR>
<FORM NAME=&quot;Email&quot; METHOD=&quot;POST&quot; ACTION=&quot;Communication.asp&quot;>
<TABLE BORDER=&quot;0&quot;>
<TR>
<TD COLSPAN=&quot;3&quot; ALIGN=&quot;CENTER&quot;>
<SPAN CLASS=&quot;JobHead&quot;>Select Email Group(s) To Send Email To</SPAN>
</TD>
</TR>
<TR>
<TD ALIGN=&quot;CENTER&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;toWho&quot; VALUE=&quot;Officers&quot;>
<SPAN CLASS=&quot;JobText&quot;>Officers</SPAN>
</TD>
<TD ALIGN=&quot;CENTER&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;toWho&quot; VALUE=&quot;Directors&quot;>
<SPAN CLASS=&quot;JobText&quot;>Directors</SPAN>
</TD>
<TD ALIGN=&quot;CENTER&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;toWho&quot; VALUE=&quot;Members&quot;>
<SPAN CLASS=&quot;JobText&quot;>Members</SPAN>
</TD>
</TR>
<TR>
<TD COLSPAN=&quot;3&quot; ALIGN=&quot;LEFT&quot; VALIGN=&quot;TOP&quot;>
<SPAN CLASS=&quot;JobText&quot;>
FROM: <INPUT NAME=&quot;fromWho&quot; TYPE=&quot;TEXT&quot; SIZE=&quot;46&quot;><BR>
SUBJECT: <INPUT NAME=&quot;Subject&quot; TYPE=&quot;TEXT&quot; SIZE=&quot;43&quot;><BR>
<TEXTAREA NAME=&quot;Body&quot; COLS=&quot;40&quot; ROWS=&quot;5&quot;></TEXTAREA><BR>
<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Send Email&quot; NAME=&quot;Submit&quot;>
</SPAN>
</TD>
</TR>
</TABLE>
</FORM>
</TD>
</TR>
</TABLE>
</TD>

<%
'Close Connection
'RS.Close
Con.Close
'Set RS = NOTHING
Set Con = NOTHING
%>
<!-- #INCLUDE FILE=&quot;Includes/footer.asp&quot; -->









 
Hi coffeyk...

This script is using CDONTS for sending email which is the built in IIS dll for sending emails. CDONTS from my experience is more trouble than it is worth. Depending on what software is installed, it may or may not work. I have had some web servers installed where it works fine, and I have also had others where it just won't send the mail. Sometimes it can be that you have to change the security permissions somewhere, and other times, you need a registery hack. All these things are not recommended, and you can read about them at microsofts website.

Instead, it is recommended that if you are able to, you should install a third party product like the one in my previous post. has a program which you install on your webserver. It runs as a service, and is very easy to use. (See my above example in previous post). Just install this product (for free) then change the mail code in your script to use the syntax in my example, and change the Server.CreateObject(&quot;CDONTS.NewMail&quot;) to Server.CreateObject(&quot;Persists.MailSender&quot;). Brett Birkett B.Comp
Systems Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top