Help converting CDONTS script to use Windows 2003 CDO

This is the script that is setup using CDONTS and I need it converted to CDO to send mail.  I have tryed to use scripts on the Internet but something does not match up correctly.  Any advise would help me out alot!!


<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage

strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = "From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")
%>
<%

          Set objNewMail = Server.CreateObject ("CDONTS.NewMail")
                objNewMail.cc = "email@address.com"
          objNewMail.BodyFormat = 1
          objNewMail.MailFormat = 0
          on error resume next '## Ignore Errors
          objNewMail.Send strSender, strRecipients, strSubject, strMessage
          If Err <> 0 Then
               Err_Msg = Err_Msg & "<li>Your request was not sent due to the following error: " & Err.Description & "</li>"
          End if
          on error resume next '## Ignore Errors
Set objNewMail = Nothing
%>
kmiller7Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fz2hqsCommented:
Are mails not being sent?
What happens when you tien the on error resume next off ?
0
fz2hqsCommented:
Sorry ignore that comment ! Just re-read the code you posted try this:


<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage

strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = "From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")


Set objNewMail = CreateObject("CDO.Message")

      objNewMail.From = strSender
      objNewMail.To = strRecipients
      objNewMail.Subject = strSubject
      objNewMail.Textbody = strMessage
      objNewMail.Configuration.Fields.Item ("cdo/configuration/sendusing">http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      objNewMail.Configuration.Fields.Item ("cdo/configuration/smtpserver">http://schemas.microsoft.com/cdo/configuration/smtpserver") = "MySMTPHost"
      objNewMail.Configuration.Fields.Item ("cdo/configuration/smtpserverport">http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      objNewMail.Configuration.Fields.Update
      objNewMail.Send

Set objNewMail = Nothing
%>
0
fz2hqsCommented:
And make sure you put something else in that "MySMTPHost" more useful like the IP or name of an SMTP Server
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

kmiller7Author Commented:
Hi,
I inserted the code but received this error -

Microsoft VBScript compilation error '800a03ee'

Expected ')'

/gallery/sendpicture.asp, line 24

objNewMail.Configuration.Fields.Item ("cdo/configuration/sendusing">http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
------------------------------------------------------------------------^


Can I also have the CC mail address in there?  The 21st line down from the original code.
0
fz2hqsCommented:
Have a look at the MS KB article on it

http://support.microsoft.com/?kbid=265527
0
kmiller7Author Commented:
I have the server name at the end - ("cdo/configuration/smtpserver">http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.ampsrc.com" also just tried ampsrc.com

But it gives me this error - HTTP 500 - Internal server error
Internet Explorer
0
kmiller7Author Commented:
If this will help to see what it is used for - http://www.ampsrc.com/gallery/pic.asp?iCat=56&iPic=201 

click email picture to a friend link.

0
kmiller7Author Commented:
There is an example on the host that uses this in the code -

Dim Flds
Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
Flds.Update
0
kmiller7Author Commented:
Any Idea what the problem is?
0
fz2hqsCommented:
This script I know works:

Set objMail = Server.CreateObject("CDO.Message")
With objMail
     .From = Your_From_Address
     .To = Your_To_Address
     .Subject = Your_Subject
     .HTMLBody = Message_Body
     .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Your_Machine_Name"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     .Configuration.Fields.Update
     .Send
End With

Set objMail = Nothing

Make sure you put in the correct machine name as per http://support.microsoft.com/?kbid=265527
0
kmiller7Author Commented:
Thank you for responding but How will this help me if I don't know how to change this to work with the rest of my script?  I have included the old CDONTS and was hoping it could be re-written to work with CDO.  I can use your script but it will not work with the form that it is used with.  This is sombody elses code to start with but when my server upgraded to Windows 2003 I have to change this to work with the new mail system CDO.
Any other ideas?

Set objNewMail = Server.CreateObject("CDO.Message")
With objNewMail
     objNewMail.From = Your_From_Address
     objNewMail.CC = Your_To_Address
     .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ampsrc.com"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     .Configuration.Fields.Update
     objNewMail.Send  strSender, strRecipients, strSubject, strMessage

End With

Set objNewMail = Nothing
0
fz2hqsCommented:
<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage

strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = "From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")


Set objMail = Server.CreateObject("CDO.Message")
With objMail
     .From = strSender
     .To = strRecipients
     .Subject = strSubject
     .HTMLBody = strMessage
     .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ampsrc.com"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     .Configuration.Fields.Update
     .Send
End With

Set objMail = Nothing
%>
0
kmiller7Author Commented:
This is at least giving me different errors now.

CDO.Message.1 error '8004020d'

At least one of the From or Sender fields is required, and neither was found.

/gallery/sendpicture.asp, line 28


28    .Send

My original CDONTS script uses this - objNewMail.Send strSender, strRecipients, strSubject, strMessage

Is CDO setup so it has to be totally constructed different?

The link above will show you the error directly.
0
kmiller7Author Commented:
Can you give me any more to help me with this script?
0
fz2hqsCommented:
What you error suggested:

"At least one of the From or Sender fields is required, and neither was found. "

Means that the the email addresses are wrong or have got mangeled try this:

<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage

strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = "From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")


Response.write "From = " & strSender & "<BR>"
Response.write "To = " & strRecipients & "<BR>"
Response.write "Subject = " & strSubject  & "<BR>"
Response.write "HTMLBody = " & strMessage
%>

What appears on the screen when you submit?
0
kmiller7Author Commented:
That seem to make it worse -

From =
To =
Subject = From: Picture
HTMLBody = Hello You received this from :
CDO.Message.1 error '8004020d'

At least one of the From or Sender fields is required, and neither was found.

/gallery/sendpicture.asp, line 33



script number -

33      .Send
0
fz2hqsCommented:
It would seem that the form being submitted to this page is not passing the form elements. The simple fact is that those response.write comments should give a "FRom = someone@domain.com" becase these are blank, then the email fails as it has no recipients

This means either
1. The form is misbehaving in some way
2. You have the wrong names for the form fields
0
kmiller7Author Commented:
The script pulls the email address from the form that is at the bottom of this send script.  The CDONTS script at the top of this page works fine but uses CDONTS.  I can email you the whole script but it is mainly just a form with the variables that are declared at the top of this script.  I can give you more points if this will help me get this script converted to CDO mail?
0
fz2hqsCommented:
Don't worry about the points. Please post up the html form and the complete original CDONTS page
0
kmiller7Author Commented:
Ok, here is the complete CDONTS sendpicture script -


<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage

strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = "From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")
%>
<%

            Set objNewMail = Server.CreateObject ("CDONTS.NewMail")
                objNewMail.cc = "picture@ampsrc.com"
            objNewMail.BodyFormat = 1
            objNewMail.MailFormat = 0
            on error resume next '## Ignore Errors
            objNewMail.Send strSender, strRecipients, strSubject, strMessage
            If Err <> 0 Then
                  Err_Msg = Err_Msg & "<li>Your request was not sent due to the following error: " & Err.Description & "</li>"
            End if
            on error resume next '## Ignore Errors
Set objNewMail = Nothing
%>

<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<p align="center"><b><font face="2" size="4">Send Picture from AMPS Gallery to
  a Friend</font></b></p>

<form action="sendpicture.asp?" method=post id=Form1 name=Form1>
<input type=hidden name="Page" value="<% =Request.QueryString %>">
      
<table border="0" width="100%%" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#e4e4e4">
    <div align="center">
      <center>
    <table border="0" width="100%" cellspacing="1" cellpadding="1">
      <TR>
        <TD bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size="2">Your
          Friend's Name:</font></b></td>
        <TD bgColor=#e4e4e4><input type=text name="Name" size=25></td>
      </tr>
      <TR>
        <TD bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size="2">Your
          Friend's Email:</font></b></td>
        <TD bgColor=#e4e4e4><input type=text name="Email" size=25></td>
      </tr>                
      <tr>
   
        <td bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size=2>Your Name:</font></b></td>
        <td bgColor=#e4e4e4><input name=YName type=<% if YName <> "" then Response.Write("hidden") else Response.Write("text") end if%> value="<% = YName %>" size=25><font face="arial" size=2> <% if YName <> "" then Response.Write(YName) end if %></font></td>
      </tr>
      <tr>
        <td bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size=2>Your Email:</font></b></td>
        <td bgColor=#e4e4e4><input name=YEmail type=<% if YEmail <> "" then Response.Write("hidden") else Response.Write("text") end if %> value="<% = YEmail %>" size=25><font face="arial" size=2> <% if YEmail <> "" then Response.Write(YEmail) end if %></font></td>
      </tr>

      <tr>
        <td bgColor=#e4e4e4 colspan=2 nowrap>
          <p align="center"><b><font face="arial" size=2>Message:</font></b></p>
        </td>
      </tr>
      <tr>
        <td bgColor=#e4e4e4 colspan=2 align=center><textarea name="Msg" cols="40" rows=11 readonly><% =vbCrLf %>A friend has sent you a photo from www.AMPSrc.com picture gallery page: Just click the link below to view the picture.<% =vbCrLf & vbCrLf & Request.QueryString("url") %></textarea></td>
      </tr>                    
      <tr>
        <td bgColor=#e4e4e4 colspan=2 align=center><input type=submit value="Send" id=Submit1 name=Submit1 onClick="MM_validateForm('Name','','R','Email','','RisEmail','YName','','R','YEmail','','RisEmail');return document.MM_returnValue"></td>
      </tr>
    </table>
      </center>
    </div>
    </td>
  </tr>
</table>
</form>
0
fz2hqsCommented:
Lets jsut test a quick theory: prove that the CDO object can send mail:

Save the following in a page called mailtext.asp within the webiste, adjust teh to address to your own, then browse to the page
<%

Set objMail = Server.CreateObject("CDO.Message")
With objMail
     .From = "test@ampsrc.com"
     .To = <YOUR EMAIL ADDRESS HERE"
     .Subject = "Test Email"
     .HTMLBody = "There is no message body"
     .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ampsrc.com"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     .Configuration.Fields.Update
     .Send
End With

Set objMail = Nothing
%>
0
kmiller7Author Commented:
I did put up this script and it did send me back this message - There is no message body

So the CDO part works it just needs to fit with the rest of the form and its variables.

0
fz2hqsCommented:
Try for a moment replacing:

<input type=submit value="Send" id=Submit1 name=Submit1 onClick="MM_validateForm('Name','','R','Email','','RisEmail','YName','','R','YEmail','','RisEmail');return document.MM_returnValue">

with

<input type=submit value="Send" id=Submit1 name=Submit1>

This will elimiate the javascript causing any issues
0
kmiller7Author Commented:
I now receive this error -

From =
To =
Subject = From: Picture
HTMLBody = Hello You received this from : From =
To =
Subject = From: Picture
HTMLBody = Hello You received this from :
CDO.Message.1 error '8004020d'

At least one of the From or Sender fields is required, and neither was found.

/gallery/sendpicture.asp, line 40

script line number -
40      .Send
0
fz2hqsCommented:
OK, remove the debug lines

Response.write "From = " & strSender & "<BR>"
Response.write "To = " & strRecipients & "<BR>"
Response.write "Subject = " & strSubject  & "<BR>"
Response.write "HTMLBody = " & strMessage

annd put that last bit back as it was, then if you can please copy and paste the full page here
0
kmiller7Author Commented:
Error -

CDO.Message.1 error '8004020d'

At least one of the From or Sender fields is required, and neither was found.

/gallery/sendpicture.asp, line 31

Script line 31 -
31  .Send


Here is complete script again -


<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage

strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = "From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")

%>

<%

Set objMail = Server.CreateObject("CDO.Message")
With objMail
     .From = strSender
     .To = strRecipients
     .Subject = strSubject
     .HTMLBody = strMessage
     .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ampsrc.com"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     .Configuration.Fields.Update
     .Send
End With

Set objMail = Nothing
%>
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<p align="center"><b><font face="2" size="4">Send Picture from AMPS Gallery to
  a Friend</font></b></p>

<form action="sendpicture.asp?" method=post id=Form1 name=Form1>
<input type=hidden name="Page" value="<% =Request.QueryString %>">
      
<table border="0" width="100%%" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#e4e4e4">
    <div align="center">
      <center>
    <table border="0" width="100%" cellspacing="1" cellpadding="1">
      <TR>
        <TD bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size="2">Your
          Friend's Name:</font></b></td>
        <TD bgColor=#e4e4e4><input type=text name="Name" size=25></td>
      </tr>
      <TR>
        <TD bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size="2">Your
          Friend's Email:</font></b></td>
        <TD bgColor=#e4e4e4><input type=text name="Email" size=25></td>
      </tr>                
      <tr>
   
        <td bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size=2>Your Name:</font></b></td>
        <td bgColor=#e4e4e4><input name=YName type=<% if YName <> "" then Response.Write("hidden") else Response.Write("text") end if%> value="<% = YName %>" size=25><font face="arial" size=2> <% if YName <> "" then Response.Write(YName) end if %></font></td>
      </tr>
      <tr>
        <td bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size=2>Your Email:</font></b></td>
        <td bgColor=#e4e4e4><input name=YEmail type=<% if YEmail <> "" then Response.Write("hidden") else Response.Write("text") end if %> value="<% = YEmail %>" size=25><font face="arial" size=2> <% if YEmail <> "" then Response.Write(YEmail) end if %></font></td>
      </tr>

      <tr>
        <td bgColor=#e4e4e4 colspan=2 nowrap>
          <p align="center"><b><font face="arial" size=2>Message:</font></b></p>
        </td>
      </tr>
      <tr>
        <td bgColor=#e4e4e4 colspan=2 align=center><textarea name="Msg" cols="40" rows=11 readonly><% =vbCrLf %>A friend has sent you a photo from www.AMPSrc.com picture gallery page: Just click the link below to view the picture.<% =vbCrLf & vbCrLf & Request.QueryString("url") %></textarea></td>
      </tr>                    
      <tr>
        <td bgColor=#e4e4e4 colspan=2 align=center><input type=submit value="Send" id=Submit1 name=Submit1>
</td>
      </tr>
    </table>
      </center>
    </div>
    </td>
  </tr>
</table>
</form>

0
fz2hqsCommented:
I think I have just realised what it is change the top section to this:

<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage

strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = "From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")

If (("" & strSender) <> "" ) and (("" & strRecipients) <> "" ) Then

Set objMail = Server.CreateObject("CDO.Message")
With objMail
     .From = strSender
     .To = strRecipients
     .Subject = strSubject
     .HTMLBody = strMessage
     .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ampsrc.com"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     .Configuration.Fields.Update
     .Send
End With

Set objMail = Nothing

End If
%>




0
kmiller7Author Commented:
The script now works except for the link inside the email is not hyper linked like it used to be.
When a friend receives this email all they have to do is click on the link to take them to the website picture that someone has selected for them to look at.

This is great that it is now working!
0
fz2hqsCommented:
I'm sorry it took a while - what was happening was when a user visited the page an email was sent immediately, in the old script it was masked by the on error resume next, however if you looked at the old server you would see a huge amount of bad mail. That If clause checks that a sender and recipient address is available before sending.

No link you say:
Is it just one person ?
Is it arriving in HTML format ?
0
kmiller7Author Commented:
I have all the right links in the email, they are not hyperlinked where you can just click on it.
There are two links that are in the email one is the website - www.ampsrc.com and the other is the picture link: example - http://www.ampsrc.com/gallery/pic.asp?iPic=196

So, the email is not arriving in HTML format!!
0
fz2hqsCommented:
Is it just to one person, do you also get it in plain text ?
0
kmiller7Author Commented:
Here is what it looks like -

Hello Kirk Miller A friend has sent you a photo from www.AMPSrc.com picture gallery page: Just click the link below to view the picture. http://www.ampsrc.com/gallery/pic.asp?iPic=196 You received this from : KM kmiller7@bigfoot.com


So, the www.ampsrc.com is not a link and the link to the picture is not a link, it is just text.
0
kmiller7Author Commented:
I looked on the Internet and it looks like the HTML body has to be formed -

' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"

But how do you add in the strMessage Variable?

This is helping me out a lot in learning ASP code!!
0
fz2hqsCommented:
Replace the strMessage section

strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")

with

strMessage = "<HTML><BODY>Hello " & Request.Form("Name") & "<BR><BR>"
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail") & "</BODY></HTML>


Then at the bottom of the page replace

       <td bgColor=#e4e4e4 colspan=2 align=center><textarea name="Msg" cols="40" rows=11 readonly><% =vbCrLf %>A friend has sent you a photo from www.AMPSrc.com picture gallery page: Just click the link below to view the picture.<% =vbCrLf & vbCrLf & Request.QueryString("url") %></textarea></td>

with

       <td bgColor=#e4e4e4 colspan=2 align=center><textarea name="Msg" cols="40" rows=11 readonly><% =vbCrLf %>A friend has sent you a photo from <A HREF="www.AMPSrc.com">www.AMPSrc.com</A> picture gallery page: Just click the link below to view the picture.  <AHREAF="<%=Request.QueryString("url") %>"><%=Request.QueryString("url") %></A></textarea></td>
0
kmiller7Author Commented:
It gives me this error now -

strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail") & "</BODY></HTML>

I changed the last line to this -

strSender = Request.Form("YEmail") & "</BODY></HTML>
but it gives errors too.

I added a " at the end of the lines but this gives errors now -

strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail") & "</BODY></HTML>"

Getting close though!
0
zenlion420Commented:
fz2hqs,

I have been monitoring this Q for about a week now, as requested by the director of CS.  I'll watch for the closing of this question (although I feel the original Q has been answered).  When it is closed, I will be posting a "points for:" link for you here.  Please take a moment to respond, and collect the points (500).

zenlion420
EE Page Editor
0
fz2hqsCommented:
Thanks, I was wondering what more I had to do to earn them !!


kmiller, don't want to leave you without this, Here is what I think the entire page should be:

<%

Dim strSender
Dim strRecipientsName
Dim strRecipients
Dim strSubject
Dim strMessage


strRecipientsName = Request.Form("Name")
strRecipients = Request.Form("Email")
strSubject = ""<HTML><BODY>From: " & Request.Form("YName") & " Picture"
strMessage = "Hello " & Request.Form("Name") & vbCrLf & vbCrLf
strMessage = strMessage & Request.Form("Msg") & vbCrLf & vbCrLf
strMessage = strMessage & "You received this from : " & Request.Form("YName") & " " & Request.Form("YEmail")
strSender = Request.Form("YEmail")


If (("" & strSender) <> "" ) and (("" & strRecipients) <> "" ) Then

Set objMail = Server.CreateObject("CDO.Message")
With objMail
     .From = strSender
     .To = strRecipients
     .Subject = strSubject
     .HTMLBody = strMessage
     .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ampsrc.com"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     .Configuration.Fields.Update
     .Send
End With

Set objMail = Nothing

End If

%>
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<p align="center"><b><font face="2" size="4">Send Picture from AMPS Gallery to
  a Friend</font></b></p>

<form action="sendpicture.asp?" method=post id=Form1 name=Form1>
<input type=hidden name="Page" value="<% =Request.QueryString %>">
     
<table border="0" width="100%%" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#e4e4e4">
    <div align="center">
      <center>
    <table border="0" width="100%" cellspacing="1" cellpadding="1">
      <TR>
        <TD bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size="2">Your
          Friend's Name:</font></b></td>
        <TD bgColor=#e4e4e4><input type=text name="Name" size=25></td>
      </tr>
      <TR>
        <TD bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size="2">Your
          Friend's Email:</font></b></td>
        <TD bgColor=#e4e4e4><input type=text name="Email" size=25></td>
      </tr>                
      <tr>
   
        <td bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size=2>Your Name:</font></b></td>
        <td bgColor=#e4e4e4><input name=YName type=<% if YName <> "" then Response.Write("hidden") else Response.Write("text") end if%> value="<% = YName %>" size=25><font face="arial" size=2> <% if YName <> "" then Response.Write(YName) end if %></font></td>
      </tr>
      <tr>
        <td bgColor=#e4e4e4 align="right" nowrap><b><font face="arial" size=2>Your Email:</font></b></td>
        <td bgColor=#e4e4e4><input name=YEmail type=<% if YEmail <> "" then Response.Write("hidden") else Response.Write("text") end if %> value="<% = YEmail %>" size=25><font face="arial" size=2> <% if YEmail <> "" then Response.Write(YEmail) end if %></font></td>
      </tr>

      <tr>
        <td bgColor=#e4e4e4 colspan=2 nowrap>
          <p align="center"><b><font face="arial" size=2>Message:</font></b></p>
        </td>
      </tr>
      <tr>
        <td bgColor=#e4e4e4 colspan=2 align=center><textarea name="Msg" cols="40" rows=11 readonly>A friend has sent you a photo from <A HREF="www.AMPSrc.com">www.AMPSrc.com</A> picture gallery page: Just click the link below to view the picture.<BR><BR><A HREF="<%=Request.QueryString("url") %>"><%=Request.QueryString("url") %></a></textarea></td>
      </tr>                    
      <tr>
        <td bgColor=#e4e4e4 colspan=2 align=center><input type=submit value="Send" id=Submit1 name=Submit1>
</td>
      </tr>
    </table>
      </center>
    </div>
    </td>
  </tr>
</table>
</form>
0
zenlion420Commented:
fz2hqs: http://www.experts-exchange.com/Web/Web_Servers/IIS/Q_20823954.html

Thanks for going above and beyond :)

j

zenlion420
EE Page Editor
0
fz2hqsCommented:
These points just earned me "Master" status, so you know, every cloud - silver lining etc etc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kmiller7Author Commented:
Thank you for your help Stuart ,

I know I probably took up to much of your time.
It seems to me that the new CDO system should be easyer to use then CDONT but as I am finding out MS wants us to jump through hoops to get this to work.

The code has this error -

/gallery/sendpicture.asp, line 12

strSubject = ""<HTML><BODY>From: " & Request.Form("YName") & " Picture"
---------------------------------^
 12 strSubject = ""<HTML><BODY>From: " & Request.Form("YName") & " Picture"

But I will have to let you go I guess!!
Thanks again
Kirk Miller
0
fz2hqsCommented:
Typing error by me note there should one be one speech mark and not two at the start of the line

strSubject = "<HTML><BODY>From: " & Request.Form("YName") & " Picture"
0
zenlion420Commented:
>> These points just earned me "Master" status, so you know, every cloud - silver lining etc etc

Congrats :)

zenlion420
EE Page Editor
0
sasanm1978Commented:
Hi,
just had some problems with mail functions after updating form 2000 to 2003

it uses cdosys instead of cdonts

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
Function Sendmail (strFrom, strTo, strSubject, strBody, BoolBodyFormat)

      Dim iMsg
      Set iMsg = CreateObject("CDO.Message")
      if strTo <> "" then

            iMsg.To = strTo
            iMsg.From = strFrom
            iMsg.Subject = strSubject
            iMsg.HTMLBody = strBody
            iMsg.Send
      end if

End Function
</SCRIPT>

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.