View Full Version : ASPMail & MS Access
tigger69
03-20-2003, 01:57 PM
Ok looking for some help from the coding Gods. I have a contact page that the info to be dumped into an MS Access data and also have the info sent out in email. Currently I can do one or the other and I need to find away to do both. I am using ASPMail 4.x and MS Access 2000 on a Windows 2000 server running IIs5.0 If anyone can point me in the right direction for this that would be great.
Thanks
Why not use CDONTS for the mailing ?
Write the data to your database, and then create a new mail with CDONTS and send the mail, using the same data (request.form ("blablabla"). Only a few lines of code (3 mostly) are needed to create and send the mail. If you run a search in this forum on CDONTS there willturn up plenty of threads about this.
Here's some more info from the helpfile:
-------------------------
NewMail Object (CDONTS Library)
The NewMail object provides for sending a message with very few lines of code.
At a Glance
Specified in type library: CDONTS.DLL
First available in: CDO for NTS Library version 1.2
Parent objects: (none)
Child objects: (none)
Default property: Value
Properties
Name Available since version
Type
Access
Bcc 1.2 String Write-only
Body 1.2 IStream object or String Write-only
BodyFormat 1.2 Long Write-only
Cc 1.2 String Write-only
ContentBase 1.2 String Write-only
ContentLocation 1.2 String Write-only
From 1.2 String Write-only
Importance 1.2 Long Write-only
MailFormat 1.2 Long Write-only
Subject 1.2 String Write-only
To 1.2 String Write-only
Value 1.2 String Write-only
Version 1.2 String Read-only
Methods
Name Available since version
Parameters
AttachFile 1.2 Source as Object or String,
(optional) FileName as String,
(optional) EncodingMethod as Long
AttachURL 1.2 Source as Object or String,
ContentLocation as String,
(optional) ContentBase as String,
(optional) EncodingMethod as Long
Send 1.2 (optional) From as String,
(optional) To as String,
(optional) Subject as String,
(optional) Body as Object or String,
(optional) Importance as Long
SetLocaleIDs 1.2 CodePageID as Long
Remarks
The NewMail object is not built on the normal API architecture. It is meant for rapid generation of notification mail by an automated process running in the Microsoft® Windows NT® Server. No user interface is supplied, and no interaction with human users is expected during the generation and sending of the message. Therefore the NewMail object's properties are not designed to be read back and inspected. With the sole exception of Version, they can only be written.
The NewMail object is self-contained and does not expose any of the Properties Common to All CDO for NTS Library Objects.
Attachments and recipients, once added to the NewMail object, cannot be removed, and the NewMail object itself cannot be deleted. When the Send method completes successfully, the NewMail object is invalidated but not removed from memory. The programmer should Set the invalid object to Nothing to remove it from memory, or reassign it to another NewMail object. Attempted access to a sent NewMail object results in a return of CdoE_INVALID_OBJECT.
The NewMail object does not belong to the hierarchy encompassing the other CDO for NTS Library objects. It cannot access, nor can it be accessed from, any of the other objects. Like the Session object, it is considered a top-level object and is created directly from a Microsoft® Visual Basic® program. Its ProgID is CDONTS.NewMail. This code fragment creates a NewMail object through early binding:
Dim objNewMail As CDONTS.NewMail
Set objNewMail = CreateObject("CDONTS.NewMail")
The main advantage of the NewMail object is the ease and simplicity with which you can generate and send a message. You do not have to log on to a session nor deal with a folder or a messages collection. You have only to create the NewMail object, send it, and Set it to Nothing. You can supply critical information in the parameters of the Send method. In many cases you only need three lines of code:
Set objNewMail = CreateObject("CDONTS.NewMail")
objNewMail.Send("me@company.com", "you@company.com", "Hello", _
"I sent this in 3 statements!", 0) ' low importance
Set objNewMail = Nothing ' canNOT reuse it for another message
Including an attachment can add as little as one statement to your code, because you can pass information in the parameters of the AttachFile method:
Set objNewMail = CreateObject("CDONTS.NewMail")
objNewMail.AttachFile("\\server\schedule\sched.xls", "SCHED.XLS")
objNewMail.Send("Automated Schedule Generator", "you@company.com", _
"Schedule", "Here's the latest master schedule", 0)
Set objNewMail = Nothing
arnyinc
03-20-2003, 02:23 PM
We have problems with CDONTS when sending to a relatively short list of email addresses. It does a complete core dump and crashes the ASP service when we try to send an email to about 40 people.
edit: nevermind, this was actually with a ChiliSoft component on UNIX, not CDONTS. Oops :o
tigger69
03-20-2003, 02:33 PM
Well part of the reason I am using ASPMail is because after reading page after page of info on CDONTS I have not be able to get it to work but I can make ASPMail work that is why I was hoping that maybe I was missing a little something in my code that would allow me to do both.
tigger69
03-21-2003, 01:40 AM
Ok got CDONTS working anyone want to help with a clue on how I could use CDONTS with MS Access? So I can have a user input info into a form and that form send the data to the MS Access database as well as email the info out.
everything you need for creating the mail from a form + sending it with CDONTS is here
http://www.oakton.net/htdocs/handouts/cdonts.asp
including source for form and asp page (buttom of page).
You can first insert it in your db, check the number of inserted records and then create and send the email.
Do you also need some code for this?
Here it is anyway. Of course you need to modify it and change the db-name, tablename and variable names
<%option explicit%>
<%@ LANGUAGE="VBSCRIPT" %><% Response.Buffer=True %>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Add record</title>
</head>
<body>
<center>
<%
dim sql, numberinserted
sql="INSERT INTO table (var1, var2, var3, var4) VALUES ('value1', 'value2', 'value3', 'value4')"
sql=replace(sql,"value1",replace(request.form("variabele1"),"'","''")) 'replace value1 with value from form.
sql=replace(sql,"value2",replace(request.form("variabele2"),"'","''")) 'second replace to prevent problems with single quotes
sql=replace(sql,"value3",replace(request.form("variabele3"),"'","''")) 'all variables are considered as text variables.
sql=replace(sql,"value4",replace(request.form("variabele4"),"'","''"))
dim condb
set condb=server.CreateObject("adodb.connection")
condb.Open("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("database.mdb"))
condb.Execute sql,numberinserted
'comment: numberinserted is a parameter that return the number of records that are inserted
condb.Close
set condb = nothing
if numberinserted=1 then
your code to build and send email
else
response.write("Problem. Data was not saved in db. There was no mail sent")
end if
%>
</center>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.