send cdo e-mail with database data

send cdo e-mail with database data

am 06.08.2007 16:43:52 von geoff.agnew

hi,

i've got a database in ms access. using ASP (vbscript) and IIS. I can
send text e-mails through ASP but i want to attach a file from the
database to the e-mail when it is sent. can anyone give me any hints
on how to get the data from access, attach it to the e-mail and send
it on? any help would be awesome

RE: send cdo e-mail with database data

am 07.08.2007 17:36:01 von JimRodgers

"joeyjoejnr" wrote:

> hi,
>
> i've got a database in ms access. using ASP (vbscript) and IIS. I can
> send text e-mails through ASP but i want to attach a file from the
> database to the e-mail when it is sent. can anyone give me any hints
> on how to get the data from access, attach it to the e-mail and send
> it on? any help would be awesome
>



You may have multiple questions there, and I'm not sure the
main one is an ASP question, but here goes.

Here's a link that may answer your question about attachments:

http://www.microsoft.com/mspress/books/sampchap/3449.aspx

Here is a link to MS where you can search for fast answers to
questions like these:

http://technet.microsoft.com/en-us/default.aspx

If you want to create a file to attach, you must say exactly
what type of file you need. Excel? Word? Text?

You may need to create a file system object to save strings
as a text file. You can put stuff into strings from your ADO
recordsets from your Access database (or any database).
This is a basic problem in VBScript and ADO. Maybe this is
not best addressed in this particular newsgroup.

If you need help here, try these:


http://www.microsoft.com/communities/newsgroups/list/en-us/d efault.aspx?dg=microsoft.public.scripting.vbscript


http://www.microsoft.com/communities/newsgroups/list/en-us/d efault.aspx?dg=microsoft.public.access

If you want to extract data "AS DATA," put it in a file and
send it to another technical person to be imported into another
database, then you might want to create a "comma-separated
values" (CSV) textfile, a tab-delimited text file, or an XML file
from an ADO recordset of that data you want to send.


Here is my standard library snippet for creating an XML file
from an ADO recordset:

<% Option Explicit %>
<% Response.Buffer = TRUE %>
<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1
'====================
%>

<%
'====================
%>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Whatever Page


<%
'
'====================
Dim Cnxn
Set Cnxn = Server.CreateObject("ADODB.Connection")
Cnxn.Mode = adModeReadWrite
Cnxn.CursorLocation = adUseClient
Cnxn.Open Server.MapPath("/mdb_directory/MyAccessFile.mdb")
'====================
Dim rsMyData
Set rsMyData = Server.CreateObject("ADODB.Recordset")
rsMyData.Open
'====================
If Not rsMyData.EOF
rsMyData.Save "F:\DataDirectory\MyXmlDataFile.xml", adPersistXML
End If
'====================
rsMyData.Close
Set rsMyData = Nothing
'====================
Cnxn.Close
Set Cnxn = Nothing
'====================
'
%>





And, finally, here is my standard library snippet for CDO that
includes an attachment (this is a whole asp file):


<% Option Explicit %>
<% Response.Buffer = TRUE %>
<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1
'====================
%>

<%
'====================
%>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Whatever Page


<% '
'====================
'
' Send e-mail to customer@customer-company.com...
' by connecting to port 25 of the SMTP server
'
Dim iMsg, iConf, Flds, sHost, strHTML
'
sHost = "smtp.whoever-my-isp.net"
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
'
' set the CDOSYS configuration fields to use port 25 on the SMTP server
'
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendus ing") =
cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpse rver") =
sHost

..Item("http://schemas.microsoft.com/cdo/configuration/smtpc onnectiontimeout")
= 10
.Update
End With
'
' build HTML for message body
'
strHTML = ""
strHTML = strHTML & " #002080; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size: 13px;"">" & vbCrLf
strHTML = strHTML & "Hey there," & vbCrLf
strHTML = strHTML & "

" & vbCrLf
strHTML = strHTML & "Blah, blah, blah" & vbCrLf
strHTML = strHTML & "

" & vbCrLf
strHTML = strHTML & "Cheers,

" & vbCrLf
strHTML = strHTML & "Your mother." & vbCrLf
strHTML = strHTML & ""
'
' apply the settings to the message and send it
'
With iMsg
Set .Configuration = iConf
.To = sContact_Email
.From = "no-reply@whoevermycompany.com"
.BCC = "out-chron@whoevermycompany.com"
.Subject = "Thank you for your request."
.HTMLBody = strHTML
.AddAttachment "F:\FamilyDocs\YourSpringBudget.xls"
.Send
End With
'
' cleanup of variables
'
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
'
'====================
'
%>

Re: send cdo e-mail with database data

am 17.08.2007 00:18:05 von geoff.agnew

On Aug 7, 4:36 pm, Jim Rodgers
wrote:
> "joeyjoejnr" wrote:
> > hi,
>
> > i've got a database in ms access. using ASP (vbscript) and IIS. I can
> > send text e-mails through ASP but i want to attach a file from the
> > database to the e-mail when it is sent. can anyone give me any hints
> > on how to get the data from access, attach it to the e-mail and send
> > it on? any help would be awesome
>
> You may have multiple questions there, and I'm not sure the
> main one is an ASP question, but here goes.
>
> Here's a link that may answer your question about attachments:
>
> http://www.microsoft.com/mspress/books/sampchap/3449.aspx
>
> Here is a link to MS where you can search for fast answers to
> questions like these:
>
> http://technet.microsoft.com/en-us/default.aspx
>
> If you want to create a file to attach, you must say exactly
> what type of file you need. Excel? Word? Text?
>
> You may need to create a file system object to save strings
> as a text file. You can put stuff into strings from your ADO
> recordsets from your Access database (or any database).
> This is a basic problem in VBScript and ADO. Maybe this is
> not best addressed in this particular newsgroup.
>
> If you need help here, try these:
>
> http://www.microsoft.com/communities/newsgroups/list/en-us/d efault.as...
>
> http://www.microsoft.com/communities/newsgroups/list/en-us/d efault.as...
>
> If you want to extract data "AS DATA," put it in a file and
> send it to another technical person to be imported into another
> database, then you might want to create a "comma-separated
> values" (CSV) textfile, a tab-delimited text file, or an XML file
> from an ADO recordset of that data you want to send.
>
> Here is my standard library snippet for creating an XML file
> from an ADO recordset:
>
> <% Option Explicit %>
> <% Response.Buffer = TRUE %>
> <% Response.CacheControl = "no-cache" %>
> <% Response.AddHeader "Pragma", "no-cache" %>
> <% Response.Expires = -1
> '====================
> %>
>
> <%
> '====================
> %>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
>
> Whatever Page
>
>
> <%
> '
> '====================
> Dim Cnxn
> Set Cnxn = Server.CreateObject("ADODB.Connection")
> Cnxn.Mode = adModeReadWrite
> Cnxn.CursorLocation = adUseClient
> Cnxn.Open Server.MapPath("/mdb_directory/MyAccessFile.mdb")
> '====================
> Dim rsMyData
> Set rsMyData = Server.CreateObject("ADODB.Recordset")
> rsMyData.Open
> '====================
> If Not rsMyData.EOF
> rsMyData.Save "F:\DataDirectory\MyXmlDataFile.xml", adPersistXML
> End If
> '====================
> rsMyData.Close
> Set rsMyData = Nothing
> '====================
> Cnxn.Close
> Set Cnxn = Nothing
> '====================
> '
> %>
>
>
>
> And, finally, here is my standard library snippet for CDO that
> includes an attachment (this is a whole asp file):
>
> <% Option Explicit %>
> <% Response.Buffer = TRUE %>
> <% Response.CacheControl = "no-cache" %>
> <% Response.AddHeader "Pragma", "no-cache" %>
> <% Response.Expires = -1
> '====================
> %>
>
> <%
> '====================
> %>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
>
> Whatever Page
>
>
> <% '
> '====================
> '
> ' Send e-mail to custo...@customer-company.com...
> ' by connecting to port 25 of the SMTP server
> '
> Dim iMsg, iConf, Flds, sHost, strHTML
> '
> sHost = "smtp.whoever-my-isp.net"
> Set iMsg = CreateObject("CDO.Message")
> Set iConf = CreateObject("CDO.Configuration")
> Set Flds = iConf.Fields
> '
> ' set the CDOSYS configuration fields to use port 25 on the SMTP server
> '
> With Flds
> .Item("http://schemas.microsoft.com/cdo/configuration/sendus ing") =
> cdoSendUsingPort
> .Item("http://schemas.microsoft.com/cdo/configuration/smtpse rver") =
> sHost
>
> .Item("http://schemas.microsoft.com/cdo/configuration/smtpco nnectiontimeout")
> = 10
> .Update
> End With
> '
> ' build HTML for message body
> '
> strHTML = ""
> strHTML = strHTML & " > #002080; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif;
> font-size: 13px;"">" & vbCrLf
> strHTML = strHTML & "Hey there," & vbCrLf
> strHTML = strHTML & "

" & vbCrLf
> strHTML = strHTML & "Blah, blah, blah" & vbCrLf
> strHTML = strHTML & "

" & vbCrLf
> strHTML = strHTML & "Cheers,

" & vbCrLf
> strHTML = strHTML & "Your mother." & vbCrLf
> strHTML = strHTML & ""
> '
> ' apply the settings to the message and send it
> '
> With iMsg
> Set .Configuration = iConf
> .To = sContact_Email
> .From = "no-re...@whoevermycompany.com"
> .BCC = "out-ch...@whoevermycompany.com"
> .Subject = "Thank you for your request."
> .HTMLBody = strHTML
> .AddAttachment "F:\FamilyDocs\YourSpringBudget.xls"
> .Send
> End With
> '
> ' cleanup of variables
> '
> Set iMsg = Nothing
> Set iConf = Nothing
> Set Flds = Nothing
> '
> '====================
> '
> %>
>
>

hi,

thanks for your help, really really useful. I just need to attach
simple text just to let the person know which record in the database
they are referring to.

again, thanks for your help