|
| Subject |
Author |
Status |
Date |
Re: What is the difference between CDONTS and CDOS YS ?
|
Hesus Oliver Pecce |
|
5/30/2008 4:51:50 AM |
Hi Zebastti, Use CDOSYS instead of CDONTS. CDONTS is an obsolete component. Here is an example of how to use CDOSYS:
http://www.aspdev.org/articles/asp-cdosys/
Post Comments |
|
Re: How would I go about sending an email ..?
|
Helen Deol |
|
5/30/2008 4:54:23 AM |
Hesus, 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? Post Comments |
|
Re: Simply assign the value of email..
|
Hesus Oliver Pecce |
|
5/30/2008 4:56:13 AM |
Hi Helen, Simply assign the value of email to oMail.To field:
Post Comments |
|
Re: Got the original code
|
Helen Deol |
|
5/30/2008 4:57:09 AM |
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> Post Comments |
|
Re: Put the code below...
|
Poutt Keitis |
|
5/30/2008 4:59:29 AM |
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
Post Comments |
|
Re: Put the code below...
|
Poutt Keitis |
|
5/30/2008 4:59:41 AM |
Helen, 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
Post Comments |
|
Re: Put that code in the sub-routine
|
Helen Deol |
|
5/30/2008 5:01:14 AM |
Yes Poutu, 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, Post Comments |
|
Re: Can you post new new code?
|
Poutt Keitis |
|
5/30/2008 5:03:26 AM |
Can you post new new code?
Post Comments |
|
Re: Error message
|
Helen Deol |
|
5/30/2008 9:57:26 PM |
Pouttu, 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> Post Comments |
|
Re: Did you solve your problem?
|
Poutt Keitis |
|
5/30/2008 10:01:30 PM |
Helen, Did you solve your problem?
Post Comments |
|
Re: Something has gone wrong
|
Helen Deol |
|
5/30/2008 10:02:43 PM |
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.P age.ProcessRequestMain() +1281 Post Comments |
|
Re: I understand your problem
|
Poutt Keitis |
|
5/30/2008 10:03:57 PM |
I understand your problem.
All the time I thought you were trying to send an email from classic ASP, not from ASP.NET.
The article below explains how to send an email from classic ASP:
http://www.aspdev.org/articles/asp-cdosys/
This one explains how to send an email from ASP.NET, and this is the one you need:
http://www.aspdev.org/articles/asp.net-send-email/
I hope this helped
Post Comments |
|
Re: Thanks for the assistance
|
Helen Deol |
|
5/30/2008 10:06:36 PM |
Pouttu, 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, Post Comments |
|
Re: Do you have SMTP ser ver running on your local box?
|
Poutt Keitis |
|
5/30/2008 10:07:39 PM |
Helen, Do you have SMTP ser ver running on your local box?
The "The transport failed to connect to the server." error usually comes up when the SMTP server is not running.
The easiest thing to do is to try the ASP.NET example as it is (with single recipient). If it does work there is a problem with the email string. If it doesn't then post the error and we'll try to fix it.
How does this sound?
Post Comments |
|
Re: The sample page works fine
|
Helen Deol |
|
5/30/2008 10:09:32 PM |
The sample page works fine. Successful transmission to my outside email account.
Now, how do I get this checklist working?
Thanks for you r assistance. I forgot how frustrating coding is. Post Comments |
|
Re: Sorry for the late reply
|
Hesus Oliver Pecce |
|
5/30/2008 10:00:22 PM |
Hi Helen, 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, Post Comments |
|
Re: More errors involving this line
|
Helen Deol |
|
5/30/2008 10:05:26 PM |
Hesus, 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> Post Comments |
|
Re: You got the error
|
Hesus Oliver Pecce |
|
5/30/2008 10:10:52 PM |
Helen, You got the error above, because you tried to print the email variable, which is declared within the Page_Load subroutine.
Please insert the following 2 lines:
Response.Write("[ " & email & " ]") Response.End
immediately after the following lines:
for each email_addy in Request.Form("email_addy") email = email & email_addy & "; " next
Run the page and post the printed result here.
Thanks, Post Comments |
|
Re: This is interesting!
|
Helen Deol |
|
5/30/2008 10:12:32 PM |
Hesus, This is interesting:
[ p; a; t; h; u; b; e; r; @; p; a; c; b; e; l; l; .; n; e; t; ,; p; a; t; h; u; b; e; r; @; p; r; o; t; e; c; t; a; l; l; .; c; o; m; ]
That's my output. h Post Comments |
|
Re: So finally know what's wrong
|
Hesus Oliver Pecce |
|
5/30/2008 10:13:51 PM |
Helen, So we finally know what's wrong.  You'll have to fix the composition of the email TO list. Post Comments |
|
Re: What is your suggestion for fixing it?
|
Helen Deol |
|
5/30/2008 10:15:21 PM |
Hesus, What is your suggestion as to how to fix this? I don't see why it's inserting a semi-colon between each letter. Post Comments |
|
Re: Put numbering
|
Hesus Oliver Pecce |
|
5/30/2008 10:16:06 PM |
You can put numbering in the checkboxes' names like this:
<input type="checkbox" name="email1" value="info@aaa.com">
info@aaa.com<br />
<input type="checkbox" name="email2" value="info@bbb.com">
info@bbb.com<br />
<input type="checkbox" name="email3" value="info@ccc.com">
info@ccc.com <br />
and then just conca tenate Request("email1"), Request("email2"), etc. Post Comments |
|
Re: You've lost me
|
Helen Deol |
|
5/30/2008 10:17:12 PM |
You've lost me. Post Comments |
|
Re: Does it make sense?
|
Hesus Oliver Pecce |
|
5/30/2008 10:17:59 PM |
Something like that:
| Code: | <input type="checkbox" name="email1" value="info@aaa.com">
info@aaa.com<br />
<input type="checkbox" name="email2" value="info@bbb.com">
info@bbb.com<br />
<input type="checkbox" name="email3" value="info@ccc.com">
info@ccc.com <br />
<%
If Request("email1") <> '' Then email = email & Request("email1") & ";"
End If If Request("email2") <> '' Then email = email & Request("email2") & ";"
End If If Request("email3") <> '' Then email = email & Request("email3") & ";"
End If
%>
|
Does it make sense?
Post Comments |
|
Re: I'll try with it!
|
Helen Deol |
|
5/30/2008 10:19:23 PM |
Thanks, Hesus!
I'll give that a try.
Post Comments |
|
Re: I commented out the original concatenation
|
Helen Deol |
|
5/30/2008 10:21:20 PM |
| Code: | 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("email1") <> "" Then email = email & Request("email1") & ";"
End If If Request("email2") <> "" Then email = email & Request("email2") & ";"
End If If Request("email3") <> "" Then email = email & Request("email3") & ";"
End If If Request("email4") <> "" Then email = email & Request("email4") & ";"
End If
Response.Write("[ " & email & " ]") Response.End
'If Request.Form("email") <> "" Then 'If email <> "" Then 'If Request("email") <> "" Then Dim objMail As New MailMessage() objMail.From = "pathuber@protectall.com"
objMail.To = email objMail.Subject = Request.Form("Subject") objMail.Body = Request.Form("Message") objMail.BodyFormat = MailFormat.Text SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(objMail) 'Else 'lblResponse.Text = "Please enter an email address."
'End If End Sub |
Ok, I commented out the original concatenation of the email addresses. Numbered the email addresses. Inserted the code you supplied to concatenate the email addresses again.
Testing shows the email addresses are in the value for "email." So there's success that far.
Then I tried several options to send, all with no success. I substituted different things in the If statement at the start of the section putting the email together. In this final version here, I tried going without the If statement altogether.
Long story short, I'm getting the right values now but it's not being sent.
Where'd I go wrong this time?
Thanks,
Post Comments |
|
Re: This is an easy one
|
Hesus Oliver Pecce |
|
5/30/2008 10:25:20 PM |
This is an easy one .
Comment the following line:
Response.End
Post Comments |
|
Re: I forgot something
|
Hesus Oliver Pecce |
|
5/30/2008 10:27:13 PM |
I forgot something. You still need to check if the email variable is not empty (user has not selected any of the check boxes). If the email variable is empty and you try to send the email you'll get an error again.
Post Comments |
|
Re: Thank you very much!
|
Helen Deol |
|
5/30/2008 10:28:31 PM |
Thanks, Hesus!
Now I have to find a server to test from. Works fine on my desktop, although it isn't mailing through to our Exchange Server. But I get the email on my laptop just fine.
Thanks for your assistance.
Post Comments |
|
Re: I'm glad it worked out
|
Hesus Oliver Pecce |
|
5/30/2008 10:29:23 PM |
Ok Helen, I'm glad it worked out. Post Comments |
|