ASP Hosting sale!
Double disk space and transfer for FREE!
Limited time offer! Act Now!

aspdev | articles | tutorials | forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ASP email - CDOSYS or CDONTS?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    ASPdev.org Forum Index -> ASP programming
View previous topic :: View next topic  
Author Message
tom



Joined: 03 Dec 2004
Posts: 4

PostPosted: Wed Jan 26, 2005 4:32 pm    Post subject: ASP email - CDOSYS or CDONTS? Reply with quote

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
View user's profile Send private message
administrator
Site Admin


Joined: 01 Oct 2004
Posts: 183

PostPosted: Fri Jan 28, 2005 1:02 pm    Post subject: Reply with quote

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/



Cheers
_________________
Peter
ASP & ASP.NET Articles and Tutorials
Back to top
View user's profile Send private message
Patrickh60



Joined: 01 Feb 2006
Posts: 14
Location: Anaheim, CA

PostPosted: Wed Feb 01, 2006 6:02 pm    Post subject: Multiple Recipients Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
administrator
Site Admin


Joined: 01 Oct 2004
Posts: 183

PostPosted: Wed Feb 01, 2006 7:38 pm    Post subject: Reply with quote

Simply assign the value of email to oMail.To field:

Code:

oMail.To = email

_________________
Peter
ASP & ASP.NET Articles and Tutorials
Back to top
View user's profile Send private message
Patrickh60



Joined: 01 Feb 2006
Posts: 14
Location: Anaheim, CA

PostPosted: Thu Feb 02, 2006 3:00 pm    Post subject: Where to place "email"? Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
paul



Joined: 11 Oct 2004
Posts: 128

PostPosted: Thu Feb 02, 2006 4:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
Patrickh60



Joined: 01 Feb 2006
Posts: 14
Location: Anaheim, CA

PostPosted: Thu Feb 02, 2006 4:53 pm    Post subject: Not Yet Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
paul



Joined: 11 Oct 2004
Posts: 128

PostPosted: Thu Feb 02, 2006 4:55 pm    Post subject: Reply with quote

Patrick,

Can you post new new code?


Paul
_________________
World Countries | Survival Skills
Back to top
View user's profile Send private message
Patrickh60



Joined: 01 Feb 2006
Posts: 14
Location: Anaheim, CA

PostPosted: Thu Feb 02, 2006 5:13 pm    Post subject: New Code Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
administrator
Site Admin


Joined: 01 Oct 2004
Posts: 183

PostPosted: Thu Feb 02, 2006 9:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
paul



Joined: 11 Oct 2004
Posts: 128

PostPosted: Fri Feb 03, 2006 10:04 am    Post subject: Reply with quote

Patrick,

Did you solve your problem?


Paul
_________________
World Countries | Survival Skills
Back to top
View user's profile Send private message
Patrickh60



Joined: 01 Feb 2006
Posts: 14
Location: Anaheim, CA

PostPosted: Fri Feb 03, 2006 2:57 pm    Post subject: ARRGGHH!! Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
paul



Joined: 11 Oct 2004
Posts: 128

PostPosted: Fri Feb 03, 2006 4:38 pm    Post subject: Reply with quote

I know what your problem is Smile.

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 Smile


Paul
_________________
World Countries | Survival Skills
Back to top
View user's profile Send private message
Patrickh60



Joined: 01 Feb 2006
Posts: 14
Location: Anaheim, CA

PostPosted: Fri Feb 03, 2006 5:03 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Patrickh60



Joined: 01 Feb 2006
Posts: 14
Location: Anaheim, CA

PostPosted: Fri Feb 03, 2006 5:07 pm    Post subject: Reply with quote

paul wrote:
I know what your problem is Smile.


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 Smile
Paul


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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    ASPdev.org Forum Index -> ASP programming All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group

SQL Tutorial