|
 |
asp_cdo thread: CDNOTS attachment
Message #1 by "jingle" <jingle_yeung@h...> on Tue, 27 Mar 2001 02:45:17
|
|
How to attach file using CDNOTS in ASP programing?
where can I get the source code?
thx
Message #2 by Revon Espiritu <Revon@a...> on Tue, 27 Mar 2001 13:24:00 +0800
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C0B67E.2172CC80
Content-Type: text/plain;
charset="iso-8859-1"
set newMailObj = server.createobject("CDONTS.NewMail")
newMailObj.Attachment "filepath"
newMailObj.Send
set newMailObj = nothing
-----Original Message-----
From: jingle [mailto:jingle_yeung@h...]
Sent: Tuesday, March 27, 2001 10:45 AM
To: ASP CDO
Subject: [asp_cdo] CDNOTS attachment
How to attach file using CDNOTS in ASP programing?
where can I get the source code?
thx
---
SoftArtisans helps developers build robust, scalable Web applications!
Excel Web reports, charts: http://www.softartisans.com/excelwriter.html
File uploads: http://www.softartisans.com/saf.html
Transactional file management: http://www.softartisans.com/saf1.html
Scalability: http://www.softartisans.com/saxsession.html
ASPstudio value pack: http://www.softartisans.com/aspstudiosuite.html
Message #3 by M FAKRUTHEEN <fakru@u...> on 27 Mar 2001 00:11:03 MST
|
|
hi,
try the below coding.
Steps to Attach a File to a Message
Create a new Web application project called myEmailWebApp in Microsoft Vi
sual
InterDev on the Web server with the Posting Acceptor installed.
Add an ASP page called Default.asp to the project.
Delete the code that comes with the page by default.
Add the following code to the page:
<%@ Language=3DVBScript %>
<HTML>
<HEAD>
<%
Dim strServerURL 'Server Name including http:// protocol
strServerURL =3D "http://" + Request.ServerVariables("SERVER_NAME")
Dim strServerURLFull 'Path to subweb directory
strServerURLFull =3D strServerURL & "/myEmailWebApp"
Dim strTargetURL 'Directory where we will upload our file to
strTargetURL =3D strServerURLFull & "/uploaded_files"
Dim strRepostURL 'Path to the page we will display after our file upload
s
strRepostURL =3D strServerURLFull & "/SendMail.asp"
Dim strPathToPA 'Path to the cpshost.dll
strPathToPA =3D strServerURL & "/Scripts/cpshost.dll"
Dim strPostingURL 'Action path for our form
strPostingURL =3D strPathToPA + "?PUBLISH?" + strRepostURL
%>
</HEAD>
<BODY bgcolor=3D"white">
<!--The Form must include the enctype properties set to "multipart/form-d
ata"
or the upload will fail. -->
<FORM enctype=3D"multipart/form-data" action=3D"<%=3DstrPostingURL %>" me
thod=3D"post"
id=3D"form1" name=3D"form1">
<INPUT type=3D"hidden" name=3D"TargetURL" value=3D"<% =3D strTargetURL %>
">
<!--This hidden field is used to determine if a file post is being made.-
->
<INPUT type=3D"hidden" name=3D"bolAttach" value=3D"true">
<CENTER>
<TABLE bgcolor=3DGray border=3D1>
<tr>
<td>From:</td>
<!--Who is this message from.-->
<td><INPUT id=3D"FromBox" name=3D"FromBox" maxlength=3D"50"
value=3D"myEmail@m..."></td>
<tr>
<tr>
<!--Who is this message To.-->
<td>To:</td>
<td><INPUT id=3D"ToBox" name=3D"ToBox" maxlength=3D"50"
value=3D"myEmail@m..."></td>
<tr>
<tr>
<!--This message's Subject.-->
<td>Subject:</td>
<td><INPUT id=3D"SubjectBox" name=3D"SubjectBox" maxlength=3D"50" val
ue=3D"Email
with attachment.">
</td>
</tr>
<tr>
<!--This message's body.-->
<td colspan=3D"2"><br><br>Message:<br>
<TEXTAREA cols=3D"40" id=3D"MessageArea" name=3D"MessageArea" rows=3D
"10">Here is
the text for this message.</TEXTAREA>
<br>
</td>
</tr>
<tr>
<td colspan=3D"2" align=3D"Left" valign=3D"center">
Specify File Attachment Paths:
</td>
</tr>
<tr>
<!--Path to the file to attach to this message.-->
<td colspan=3D"2" align=3D"right" valign=3D"center">
<INPUT name=3D"my_file" type=3D"file" size=3D"20">
<br><br>
</td>
</tr>
<tr>
<!--This message's importance.-->
<td colspan=3D"2" ><br>Importance Level:
<INPUT type=3D"radio" id=3DoptImpo name=3DoptImpo value=3D0 checked>L
ow
<INPUT type=3D"radio" id=3DoptImpo name=3DoptImpo value=3D1>Medium
<INPUT type=3D"radio" id=3DoptImpo name=3DoptImpo value=3D2>High
<br></td>
<tr>
<tr>
<!--Validating Submit Button.-->
<td colspan=3D"2" align=3D"right" valign=3D"center">
<INPUT type=3D"button" value=3D"Send" id=3D"button1" name=3D"button1"
LANGUAGE=3D"javascript" onclick=3D"return button1_onclick()">
<INPUT type=3D"reset" value=3D"Reset" id=3D"reset1" name=3D"reset1">
</td>
</tr>
</TABLE>
</CENTER>
</FORM>
<SCRIPT ID=3D"clientEventHandlersJS" LANGUAGE=3D"javascript">
<!--
function button1_onclick() {
//Determine if there is a From address at all.
if(form1.FromBox.value =3D=3D"")
{
//No from Address -Stop Submission
alert("You have not typed a From: Address.");
return;
}
//Determine if there is a To address at all.
if(form1.ToBox.value =3D=3D"")
{
//No To Address -Stop Submission
alert("You have not typed a TO: Address.");
return;
}
//Determine if there is a subject at all.
if(form1.SubjectBox.value =3D=3D"")
{
//No Subject - Question Submission
//Determine if they care.
var bolCancel =3D confirm("You have not typed a Subject continue?\n");
if(bolCancel=3D=3Dfalse)
{
//User clicked Cancel -Stop Submission
return;
}
}
if(form1.MessageArea.value =3D=3D"")
{
//No Message - Question Submission
//Determine if they care.
var bolStop =3D confirm("You have not typed a Message continue?\n");
if(bolStop=3D=3Dfalse)
{
//User clicked Cancel -Stop Submission
return;
}
}
SubmitForm();
}
function SubmitForm()
{
//File counter for the number of files on the Form
var FileNumber =3D 0;
//FormMain is set to the form1 of the document
var FormMain =3D document.forms("form1");
//Loop counter
var i;
//Start at zero and loop until i is equal to the number of
//elements in the page. Step i +1 per loop through
for (i=3D0;i<FormMain.elements.length;i++)
{
if (FormMain.elements[i].name =3D=3D 'my_file' &&
FormMain.elements[i].value.length > 0)
{
FileNumber++;
}
}
//If there are files being posted then send the file to the Posting
Acceptor
//If not, skip to the send mail page with the Attachment boolean set t
o
false.
if(FileNumber=3D=3D0)
{
form1.bolAttach.value =3D "false"
form1.action =3D 'SendMail.asp';
//The encoding must be set to a different type in order to not
//use the posting acceptor.
form1.encoding =3D 'application/x-www-form-urlencoded';
form1.submit();
}
else
{
//There are files attached use normal submit.
form1.submit();
}
};
//-->
</SCRIPT>
</BODY>
</HTML>
In Visual InterDev right-click the project name in the Project Explorer a
nd
choose New Folder from the pop-up menu.
Name the new folder Uploaded_files.
Open the Internet Service Manager Console and browse to the Uploaded_file
s
folder that you created.
Right-click the folder, and then click Properties.
On the Directory tab select read/write permissions, and then click OK.
Close the Internet Services Manager.
Open Windows Explorer and browse to the MyEmailWebApp folder under the
Root:\Inetpub\Wwwroot directory.
Right-click the Uploaded_files folder, and then choose Properties.
On the Security tab make sure that the Internet guest account has
read/write/change permissions on the folder.
Click OK, and then close Windows Explorer.
In Visual InterDev, add a second page named SendMail.asp to the Web
application.
Delete the code that comes with the page by default.
Add the following code to the page:
<%@ Language=3DVBScript %>
<HTML>
<HEAD>
<TITLE>E-mail Sent Confirmation</TITLE>
</HEAD>
<BODY>
<HR>
<%
'Dim Message Variables
Dim objMsg, strFrom, strTo, strSubject,lngImportance
'Get the values to use with the message from the post.
strFrom =3D lcase(Trim(Request.Form("FromBox")))
strTo =3D lcase(Trim(Request.Form("ToBox")))
strSubject =3D Request.Form("SubjectBox")
lngImportance =3D CInt(Request.Form("optImpo"))
'Create the Message Object
Set objMsg =3D Server.CreateObject("CDONTS.NewMail")
'Set the properties of the Message
objMsg.From =3D strFrom
objMsg.To =3D strTo
objMsg.Subject =3D strSubject
'Use the actual Request Object so that you do not over load the string Da
ta
type.
objMsg.Body =3D Request.Form("MessageArea")
objMsg.Importance =3D lngImportance
'Determine if we need to attach a file.
Dim bolAttachmentPosted
bolAttachmentPosted =3D CBool(Request.Form("bolAttach"))
If bolAttachmentPosted Then
'If do then where on the server can we get it
FilePathOnServer=3D Server.MapPath("/myEmailWebApp/uploaded_files")
FilePath_Name =3D FilePathOnServer & "\" & Request.Form("FileName") &
Request.Form("FileExtention")
'Attach it
objMsg.AttachFile FilePath_Name
End If
'Send Message
objMsg.Send
'Destroy the object
Set objMsg =3D Nothing
'Determine if there is a file on the server to delete.
If bolAttachmentPosted Then
Dim FSO
'Create a File System Object
Set FSO =3D server.CreateObject ("Scripting.FileSystemObject")
'Delete the file from the server
FSO.DeleteFile FilePath_Name
'Destroy the object
Set FSO =3D Nothing
End If
'Write out results
Response.Write "The following message was sent via CDO for NTS:" & "<br>"
Response.Write "From: " & strFrom & "<br>"
Response.Write "To: " & strTo & "<br>"
Response.Write "Subject: " & strSubject & "<br>"
Response.Write "Importance: " & lngImportance & "<br>"
Response.Write "Body: " & Request.Form("MessageArea") & "<br>"
%>
</BODY>
</HTML>
Click Save All on the toolbar.
Right-click the Default.asp file, and then select View in Browser.
regards
fakru
"jingle" <jingle_yeung@h...> wrote:
How to attach file using CDNOTS in ASP programing?
where can I get the source code?
thx
Message #4 by Aftab Ahmad <aftab.ahmad@k...> on Tue, 27 Mar 2001 10:58:08 +0200
|
|
Hi
Change the code acc. to your requirement. To attach any file use the
attachment method and give full path to the file as below [i-e
objSendMail.AttachFile("C:\inetpub\wwwroot\rmFiles\intra_top1.gif") ]
<%
Set objSendMail =3D CreateObject("CDONTS.NewMail")
HTML =3D "<!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"">"
HTML =3D HTML & "<p>"
HTML =3D HTML & "<p>"
HTML =3D HTML & ""
HTML =3D HTML & "<p>"
HTML =3D HTML & "<p><font size =3D""5"" face=3D""Arial""
color=3D""green""><strong>"
HTML =3D HTML & "Risk Id: " & riskid & "</strong></font></p><br>"
HTML =3D HTML & "<a
href=3Dhttp://obelix/rm/form-update-risk.asp>Trykk her =E5
oppdatere risk</a>"
HTML =3D HTML & "<p>"
HTML =3D HTML & "<p>"
objSendMail.From=3D "aftab.ahmad@k..."
objSendMail.To=3D"aftab.ahmad@k..."
objSendMail.Subject=3D"this is sub"
objSendMail.BodyFormat=3D0
objSendMail.MailFormat=3D0
objSendMail.Body=3DHTML
objSendMail.AttachFile("C:\inetpub\wwwroot\rmFiles\intra_top1.gif")
objSendMail.Send
set objSendMail=3Dnothing
%>
-----Original Message-----
From: jingle [mailto:jingle_yeung@h...]
Sent: 27. mars 2001 04:45
To: ASP CDO
Subject: [asp_cdo] CDNOTS attachment
How to attach file using CDNOTS in ASP programing?
where can I get the source code?
thx
Message #5 by "jingle" <jingle_yeung@h...> on Thu, 29 Mar 2001 02:09:05
|
|
How can I download the file from server using ASP also?
|
|
 |