Solved

Help converting CDONTS script to use Windows 2003 CDO

Posted on 2003-12-02
43
924 Views
Last Modified: 2007-12-19
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
%>
0
Comment
Question by:kmiller7
  • 20
  • 19
  • 3
  • +1
43 Comments
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9859260
Are mails not being sent?
What happens when you tien the on error resume next off ?
0
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9859398
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9859407
And make sure you put something else in that "MySMTPHost" more useful like the IP or name of an SMTP Server
0
 

Author Comment

by:kmiller7
ID: 9859656
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9859692
Have a look at the MS KB article on it

http://support.microsoft.com/?kbid=265527
0
 

Author Comment

by:kmiller7
ID: 9859767
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
 

Author Comment

by:kmiller7
ID: 9859829
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
 

Author Comment

by:kmiller7
ID: 9859876
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
 

Author Comment

by:kmiller7
ID: 9861952
Any Idea what the problem is?
0
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9881102
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
 

Author Comment

by:kmiller7
ID: 9882709
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9883029
<%

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
 

Author Comment

by:kmiller7
ID: 9884027
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
 

Author Comment

by:kmiller7
ID: 9912872
Can you give me any more to help me with this script?
0
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9912905
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
 

Author Comment

by:kmiller7
ID: 9912969
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9913255
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
 

Author Comment

by:kmiller7
ID: 9913310
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9913333
Don't worry about the points. Please post up the html form and the complete original CDONTS page
0
 

Author Comment

by:kmiller7
ID: 9913385
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9913417
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:kmiller7
ID: 9913515
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9913564
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
 

Author Comment

by:kmiller7
ID: 9913640
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9913677
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
 

Author Comment

by:kmiller7
ID: 9913804
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9919035
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
 

Author Comment

by:kmiller7
ID: 9920669
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9920890
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
 

Author Comment

by:kmiller7
ID: 9920936
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9921013
Is it just to one person, do you also get it in plain text ?
0
 

Author Comment

by:kmiller7
ID: 9921100
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
 

Author Comment

by:kmiller7
ID: 9921420
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9921522
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
 

Author Comment

by:kmiller7
ID: 9924778
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
 
LVL 5

Expert Comment

by:zenlion420
ID: 9925877
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9926873
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
 
LVL 5

Expert Comment

by:zenlion420
ID: 9927660
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
 
LVL 9

Accepted Solution

by:
fz2hqs earned 140 total points
ID: 9927811
These points just earned me "Master" status, so you know, every cloud - silver lining etc etc
0
 

Author Comment

by:kmiller7
ID: 9927931
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
 
LVL 9

Expert Comment

by:fz2hqs
ID: 9927948
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
 
LVL 5

Expert Comment

by:zenlion420
ID: 9931936
>> These points just earned me "Master" status, so you know, every cloud - silver lining etc etc

Congrats :)

zenlion420
EE Page Editor
0
 

Expert Comment

by:sasanm1978
ID: 9935442
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Today I came across an interesting issue that had me pulling my hair out.  I was troubleshooting a new internal web site which uses integrated security instead of anonymous.  When browsing the site from my laptop, I was able to access it with no iss…
Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now