[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

sending attachment with email using CDONTs

Asked by amit_mi2 in Miscellaneous Web Development

Tags: attachment, cdonts

Hi everybody,
I'm having some problem with the utility of file attachment in the email. Whenever i'm trying to run the following code i'm getting an error message in the line 18 of SendMail.asp as "invalid class string".  I'm also confused as what to write as the "SERVER_NAME". If you people can help me in this regard i'll be highly obliged. I'm herewith attaching the codes of the two ASP files named Default.asp and SendMail.asp.

Default.asp
<%@ Language=VBScript %>
<HTML>
<HEAD>

<%
Dim strServerURL  'Server Name including http:// protocol
strServerURL = "http://" + Request.ServerVariables("SERVER_NAME")

Dim strServerURLFull 'Path to subweb directory
strServerURLFull = strServerURL & "/EmailApp"

Dim strTargetURL  'Directory where we will upload our file to
strTargetURL = strServerURLFull & "/uploaded_files"

Dim strRepostURL  'Path to the page we will display after our file uploads
strRepostURL = strServerURLFull & "/SendMail.asp"

Dim strPathToPA   'Path to the cpshost.dll
strPathToPA =  strServerURL & "/Scripts/cpshost.dll"

Dim strPostingURL 'Action path for our form
strPostingURL = strPathToPA + "?PUBLISH?" + strRepostURL
%>



</HEAD>
<BODY bgcolor="white">
<!--The Form must include the enctype properties set to "multipart/form-data" or the upload will fail. -->
<FORM enctype="multipart/form-data" action=="<% = strPostingURL %>" method="post" id="form1" name="form1">
<INPUT type="hidden" name="TargetURL" value="<% = strTargetURL %>">
<!--This hidden field is used to determine if a file post is being made.-->
<INPUT type="hidden" name="bolAttach" value="true">
      <CENTER>
            <TABLE bgcolor=Gray border=1>
                  <tr>
                        <td>From:</td>
                        <!--Who is this message from.-->
                        <td><INPUT id="FromBox" name="FromBox" maxlength="50" value=""></td>
                  <tr>
                        <!--Who is this message To.-->
                        <td>To:</td>
                        <td><INPUT id="ToBox" name="ToBox" maxlength="50" value=""></td>
                  <tr>
                        <!--This message's Subject.-->
                        <td>Subject:</td>
                        <td><INPUT id="SubjectBox" name="SubjectBox" maxlength="50" value="">
                        </td>

                  </tr>
                  <tr>
                        <!--This message's body.-->
                        <td colspan="2"><br><br>Message:<br>
                        <TEXTAREA cols="40" id="MessageArea" name="MessageArea" rows="10"></TEXTAREA>
                        <br>
                        </td>
                  </tr>
                        <tr>
                        <td colspan="2" align="Left" valign="center">
                        Specify File Attachment Paths:
                        </td>
                  </tr>
                  <tr>
                        <!--Path to the file to attach to this message.-->
                        <td colspan="2" align="right" valign="center">
                        <INPUT name="my_file" type="file" size="20">
                        <br><br>
                        </td>
                  </tr>
                  <!--<tr>-->
                        <!--This message's importance.-->
                        <!--<td colspan="2" ><br>Importance Level:
                        <INPUT type="radio" id=optImpo name=optImpo value=0 checked>Low
                        <INPUT type="radio" id=optImpo name=optImpo value=1>Medium
                        <INPUT type="radio" id=optImpo name=optImpo value=2>High
                        <br></td>
                  <tr>-->
                        <!--Validating Submit Button.-->
                        <td colspan="2" align="right" valign="center">
                        <INPUT type="button" value="Send" id="button1" name="button1" LANGUAGE="javascript" onclick="return button1_onclick()">
                        <INPUT type="reset" value="Reset" id="reset1" name="reset1">
                        </td>
                  </tr>
            </TABLE>
      </CENTER>
</FORM>
<SCRIPT ID="clientEventHandlersJS" LANGUAGE="javascript">
<!--
function button1_onclick() {
      //Determine if there is a From address at all.
      if(form1.FromBox.value =="")
      {
            //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 =="")
      {
            //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 =="")
      {
            //No Subject - Question Submission
            //Determine if they care.
            var bolCancel = confirm("You have not typed a Subject continue?\n");

            if(bolCancel==false)
            {
                  //User clicked Cancel -Stop Submission
                  return;
            }
      }
      if(form1.MessageArea.value =="")
      {
            //No Message - Question Submission
            //Determine if they care.
            var bolStop = confirm("You have not typed a Message continue?\n");

            if(bolStop==false)
            {
                  //User clicked Cancel -Stop Submission
                  return;
            }
      }
      SubmitForm();
}

function SubmitForm()
{
   //File counter for the number of files on the Form
   var FileNumber = 0;
   //FormMain is set to the form1 of the document
   var FormMain = 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=0;i<FormMain.elements.length;i++)
   {
      if (FormMain.elements[i].name == '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 to false.
   if(FileNumber==0)
   {
      form1.bolAttach.value = "false"
      form1.action = 'SendMail.asp';
      //The encoding must be set to a different type in order to not
      //use the posting acceptor.
      form1.encoding = 'application/x-www-form-urlencoded';
      form1.submit();
   }
   else
   {
   //There are files attached use normal submit.
      form1.submit();
   }
};
//-->
</SCRIPT>
</BODY>
</HTML>

SendMail.asp

<%@ Language=VBScript %>
<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 = lcase(Trim(Request.Form("FromBox")))
strTo = lcase(Trim(Request.Form("ToBox")))
strSubject = Request.Form("SubjectBox")
lngImportance = CInt(Request.Form("optImpo"))

'Create the Message Object
Set objMsg = Server.CreateObject("CDONTS.NewMail")
'Set the properties of the Message
objMsg.From = strFrom
objMsg.To = strTo
objMsg.Subject = strSubject
'Use the actual Request Object so that you do not over load the string Data type.
objMsg.Body = Request.Form("MessageArea")
objMsg.Importance = lngImportance

'Determine if we need to attach a file.
Dim bolAttachmentPosted
bolAttachmentPosted = CBool(Request.Form("bolAttach"))
If bolAttachmentPosted Then
      'If do then where on the server can we get it
      FilePathOnServer= Server.MapPath("/myEmailWebApp/uploaded_files")
      FilePath_Name = FilePathOnServer & "\" & Request.Form("FileName") & Request.Form("FileExtention")
      'Attach it
      objMsg.AttachFile FilePath_Name
End If

'Send Message
objMsg.Send

'Destroy the object
Set objMsg = Nothing
'Determine if there is a file on the server to delete.
If bolAttachmentPosted Then
      Dim FSO
      'Create a File System Object
      Set FSO = server.CreateObject ("Scripting.FileSystemObject")
      'Delete the file from the server
      FSO.DeleteFile FilePath_Name
      'Destroy the object
      Set FSO = 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>
[+][-]11/09/05 08:54 AM, ID: 15257806Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Miscellaneous Web Development
Tags: attachment, cdonts
Sign Up Now!
Solution Provided By: jr001
Participating Experts: 3
Solution Grade: A
 
[+][-]11/07/05 09:32 AM, ID: 15240693Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/05 10:17 AM, ID: 15241057Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/05 03:54 AM, ID: 15246535Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/05 08:02 AM, ID: 15248332Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/05 08:05 AM, ID: 15248374Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/05 05:54 AM, ID: 15255940Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/05 09:56 AM, ID: 15258372Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01/04/06 08:19 AM, ID: 15608745Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]01/09/06 03:18 AM, ID: 15647695Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92