| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| tom 
 
 
 Joined: 03 Dec 2004
 Posts: 4
 
 
 | 
			
				|  Posted: Wed Jan 26, 2005 4:32 pm    Post subject: ASP email - CDOSYS or CDONTS? |   |  
				| 
 |  
				| I want to send an email from ASP page. I read that I can use CDONTS and/or CDOSYS. What is the difference between CDONTS and CDOSYS and which one it's better to use? 
 
 
 Thanks,
 
 Tom
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| administrator Site Admin
 
 
 Joined: 01 Oct 2004
 Posts: 183
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Patrickh60 
 
 
 Joined: 01 Feb 2006
 Posts: 14
 Location: Anaheim, CA
 
 | 
			
				|  Posted: Wed Feb 01, 2006 6:02 pm    Post subject: Multiple Recipients |   |  
				| 
 |  
				| Peter, 
 How would I go about sending an email to multiple recipients?  I've been given the code (partial code):
 
 <form method="post" action="form1.asp">
 <input type="checkbox" name="email" value="info@aaa.com">
 info@aaa.com<br />
 <input type="checkbox" name="email" value="info@bbb.com">
 info@bbb.com<br />
 <input type="checkbox" name="email" value="info@ccc.com">
 info@ccc.com <br />
 
 Then going to form1.asp:
 
 <% dim email, email_addy, message, subject
 email = ""
 for each email_addy in Request.Form("email")
 email = email & email_addy & "; "
 next
 
 
 Using a CDOSYS example, I can send an email that has the email address coded in.  How can I pull multiple addresses that have been selected and insert them into the TO field?
 _________________
 pathuber@protectall.com
 www.protectall.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| administrator Site Admin
 
 
 Joined: 01 Oct 2004
 Posts: 183
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Patrickh60 
 
 
 Joined: 01 Feb 2006
 Posts: 14
 Location: Anaheim, CA
 
 | 
			
				|  Posted: Thu Feb 02, 2006 3:00 pm    Post subject: Where to place "email"? |   |  
				| 
 |  
				| Peter, 
 I got the original code to send an email.  Then I tried to plug in my "email" bit--adding the checked addresses into the "mail.To" line.  Various errors.  At this point I get a "Declaration Expected" error.  Is my mistake in the placement of the script that adds the email addresses together?
 
 <%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="True" %>
 <%@ Import Namespace="System.Web.Mail" %>
 <script language="VB" runat=server>
 
 Dim email
 
 email = ""
 for each email_addy in Request.Form("email_addy")
 email = email & email_addy & "; "
 next
 Sub Page_Load(Sender as Object, E as EventArgs)
 If Page.IsPostBack Then
 lblResponse.Text = "Your email has been sent."
 End If
 End Sub
 
 Sub btn_Click(sender as Object, e as System.EventArgs)
 If Request.Form("Email") <> "" Then
 Dim objMail As New MailMessage()
 objMail.From = "pathuber@protectall.com"
 ' objMail.To = Request.Form("Email")
 objMail.To = email
 objMail.Subject = Request.Form("Subject")
 objMail.Body = Request.Form("Message")
 objMail.BodyFormat = MailFormat.Text
 'SmtpMail.SmtpServer = "smtp.protectall.com"
 SmtpMail.SmtpServer = "localhost"
 SmtpMail.Send(objMail)
 Else
 lblResponse.Text = "Please enter an email address."
 End If
 End Sub
 
 </script>
 
 
 <html>
 <head>
 <style>
 .main {font-family:Verdana; font-size:12px;}
 .title {font-family:Verdana; font-size:18px; font-weight:bold;}
 </style>
 </head>
 <body>
 <span class="title" align="center">Send email from an ASP.NET page</span>
 
 <br><br><asp:Label class="main" id="lblResponse" runat="server"/>
 
 <form method="POST" name="MainForm" runat="server">
 <table ID="Table1">
 <tr>
 <td class="main" align="right">Email:</td>
 <td class="main">
 <!-- <input type="text" class="main" name="Email" value=""> -->
 <input type="checkbox" name="email_addy" value="info@aaa.com">info@aaa.com<br />
 <input type="checkbox" name="email_addy" value="abaudoin@protectall.com">abaudoin@protectall.com<br />
 <input type="checkbox" name="email_addy" value="pathuber@pacbell.net">pathuber@pacbell.net <br />
 <input type="checkbox" name="email_addy" value="pathuber@protectall.com">pathuber@protectall.com <br /></td>
 </tr>
 <tr>
 <td class="main" align="right">Subject:</td>
 <td class="main"><input type="text" class="main" name="Subject" value=""></td>
 </tr>
 <tr>
 <td class="main" align="right" valign="top">Message:</td>
 <td class="main"><textarea name="Message" cols="50" rows="8"></textarea></td>
 </tr>
 
 
 <tr>
 <td class="main"> </td>
 <td class="main"><input type="Submit" id="btnSubmit" OnServerClick="btn_Click"
 value="Send" runat="server" /></td>
 </tr>
 </table>
 </form>
 </body>
 </html>
 _________________
 pathuber@protectall.com
 www.protectall.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| paul 
 
 
 Joined: 11 Oct 2004
 Posts: 128
 
 
 | 
			
				|  Posted: Thu Feb 02, 2006 4:17 pm    Post subject: |   |  
				| 
 |  
				| Patrick, 
 Put the code below within the btn_Click sub-routine and this should fix your problem:
 
 
  	  | Code: |  	  | Dim email
 
 email = ""
 for each email_addy in Request.Form("email_addy")
 email = email & email_addy & "; "
 next
 
 | 
 
 
 
 Paul
 _________________
 World Countries | Survival Skills
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Patrickh60 
 
 
 Joined: 01 Feb 2006
 Posts: 14
 Location: Anaheim, CA
 
 | 
			
				|  Posted: Thu Feb 02, 2006 4:53 pm    Post subject: Not Yet |   |  
				| 
 |  
				| Paul, 
 I put that code in the sub-routine and got an error that email_addy was undeclared.  So I added "Dim email_addy" underneath "Dim email".  Now It comes back with the message "Please enter an email address" so it's not seeing the addresses.
 
 Your thoughts on this?
 
 Thanks,
 Pat
 _________________
 pathuber@protectall.com
 www.protectall.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| paul 
 
 
 Joined: 11 Oct 2004
 Posts: 128
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Patrickh60 
 
 
 Joined: 01 Feb 2006
 Posts: 14
 Location: Anaheim, CA
 
 | 
			
				|  Posted: Thu Feb 02, 2006 5:13 pm    Post subject: New Code |   |  
				| 
 |  
				| Paul, 
 Error message is now concerning Line 28: SmtpMail.Send(objMail):
 Server Error in '/' Application.
 --------------------------------------------------------------------------------
 
 The server rejected one or more recipient addresses. The server response was: 501 5.5.4 Invalid Address
 
 
 When it rains, it pours.
 
 Thanks!
 
 <%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="True" %>
 <%@ Import Namespace="System.Web.Mail" %>
 <script language="VB" runat=server>
 
 Sub Page_Load(Sender as Object, E as EventArgs)
 If Page.IsPostBack Then
 lblResponse.Text = "Your email has been sent."
 End If
 End Sub
 
 Sub btn_Click(sender as Object, e as System.EventArgs)
 Dim email
 Dim email_addy
 email = ""
 for each email_addy in Request.Form("email_addy")
 email = email & email_addy & "; "
 next
 If Request.Form("email_addy") <> "" Then
 Dim objMail As New MailMessage()
 objMail.From = "pathuber@protectall.com"
 ' objMail.To = Request.Form("Email")
 objMail.To = email
 objMail.Subject = Request.Form("Subject")
 objMail.Body = Request.Form("Message")
 objMail.BodyFormat = MailFormat.Text
 'SmtpMail.SmtpServer = "smtp.protectall.com"
 SmtpMail.SmtpServer = "localhost"
 SmtpMail.Send(objMail)
 Else
 lblResponse.Text = "Please enter an email address."
 End If
 End Sub
 
 </script>
 
 
 <html>
 <head>
 <style>
 .main {font-family:Verdana; font-size:12px;}
 .title {font-family:Verdana; font-size:18px; font-weight:bold;}
 </style>
 </head>
 <body>
 <span class="title" align="center">Send email from an ASP.NET page</span>
 
 <br><br><asp:Label class="main" id="lblResponse" runat="server"/>
 
 <form method="POST" name="MainForm" runat="server">
 <table ID="Table1">
 <tr>
 <td class="main" align="right">Email:</td>
 <td class="main">
 <!-- <input type="text" class="main" name="Email" value=""> -->
 <input type="checkbox" name="email_addy" value="info@aaa.com">info@aaa.com<br />
 <input type="checkbox" name="email_addy" value="abaudoin@protectall.com">abaudoin@protectall.com<br />
 <input type="checkbox" name="email_addy" value="pathuber@pacbell.net">pathuber@pacbell.net <br />
 <input type="checkbox" name="email_addy" value="pathuber@protectall.com">pathuber@protectall.com <br /></td>
 </tr>
 <tr>
 <td class="main" align="right">Subject:</td>
 <td class="main"><input type="text" class="main" name="Subject" value=""></td>
 </tr>
 <tr>
 <td class="main" align="right" valign="top">Message:</td>
 <td class="main"><textarea name="Message" cols="50" rows="8"></textarea></td>
 </tr>
 
 
 <tr>
 <td class="main"> </td>
 <td class="main"><input type="Submit" id="btnSubmit" OnServerClick="btn_Click"
 value="Send" runat="server" /></td>
 </tr>
 </table>
 </form>
 </body>
 </html>
 _________________
 pathuber@protectall.com
 www.protectall.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| administrator Site Admin
 
 
 Joined: 01 Oct 2004
 Posts: 183
 
 
 | 
			
				|  Posted: Thu Feb 02, 2006 9:07 pm    Post subject: |   |  
				| 
 |  
				| Hi Patrick, 
 Sorry for the late reply.
 
 Can you please print the value of email, with the following code:
 
 Response.Write("[ " & email & " ]")
 
 and post it here?
 
 There must be something wrong with your email string to get this error.
 
 
 
 Thanks,
 
 Peter
 _________________
 Peter
 ASP & ASP.NET Articles and Tutorials
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| paul 
 
 
 Joined: 11 Oct 2004
 Posts: 128
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Patrickh60 
 
 
 Joined: 01 Feb 2006
 Posts: 14
 Location: Anaheim, CA
 
 | 
			
				|  Posted: Fri Feb 03, 2006 2:57 pm    Post subject: ARRGGHH!! |   |  
				| 
 |  
				| Peter & Paul: 
 Something has gone tragically wrong:
 
 Server Error in '/' Application.
 --------------------------------------------------------------------------------
 
 The transport failed to connect to the server.
 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
 Exception Details: System.Runtime.InteropServices.COMException: The transport failed to connect to the server.
 
 Source Error:
 
 
 Line 24: objMail.BodyFormat = MailFormat.Text
 Line 25: SmtpMail.SmtpServer = "localhost"
 Line 26: SmtpMail.Send(objMail)
 Line 27: Else
 Line 28: lblResponse.Text = "Please enter an email address."
 
 
 Source File: c:\inetpub\wwwroot\eform3.aspx    Line: 26
 
 Stack Trace:
 
 
 [COMException (0x80040213): The transport failed to connect to the server.
 ]
 
 [TargetInvocationException: Exception has been thrown by the target of an invocation.]
 System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
 System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
 System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +58
 
 [HttpException (0x80004005): Could not access 'CDO.Message' object.]
 System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +113
 System.Web.Mail.CdoSysHelper.Send(MailMessage message) +1861
 System.Web.Mail.SmtpMail.Send(MailMessage message) +153
 ASP.eform3_aspx.btn_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\eform3.aspx:26
 System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +108
 System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
 System.Web.UI.Page.ProcessRequestMain() +1281
 _________________
 pathuber@protectall.com
 www.protectall.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| paul 
 
 
 Joined: 11 Oct 2004
 Posts: 128
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Patrickh60 
 
 
 Joined: 01 Feb 2006
 Posts: 14
 Location: Anaheim, CA
 
 | 
			
				|  Posted: Fri Feb 03, 2006 5:03 pm    Post subject: |   |  
				| 
 |  
				|  	  | administrator wrote: |  	  | Hi Patrick, 
 Sorry for the late reply.
 
 Can you please print the value of email, with the following code:
 
 Response.Write("[ " & email & " ]")
 
 
 | 
 
 Peter,
 
 I must be too far out-of-practice.  More errors involving this line.
 Compiler Error Message: BC30451: Name 'email' is not declared.
 
 Source Error:
 
 
 
 Line 72: </form>
 Line 73: <script>
 Line 74: <%Response.Write("[ " & email & " ]")%>
 Line 75: </script>
 _________________
 pathuber@protectall.com
 www.protectall.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Patrickh60 
 
 
 Joined: 01 Feb 2006
 Posts: 14
 Location: Anaheim, CA
 
 | 
			
				|  Posted: Fri Feb 03, 2006 5:07 pm    Post subject: |   |  
				| 
 |  
				| 
 Paul,
 Thanks for the assistance.  See the previous code in the thread.  This is taking me back around to square one.  I started with this code and added code to read a number of email addresses that have been checked.  I want to have a checklist of boy scout troop members.  Check the ones you want to email and have their addresses inserted into the "To:" line.
 
 I can't seem to get it without screwing up the code.
 
 I'm running this on my Win2000 desktop and it's IIS, if that makes a diffference.  Our server wouldn't run the original attempt in classic ASP.  The scout server runs ASP.Net so I made the switch.
 
 Thanks,
 Pat
 _________________
 pathuber@protectall.com
 www.protectall.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |