PDA

View Full Version : Sending email from web


bkagan98
07-28-2003, 09:07 AM
Hello,

I read all previous postings about sending emails from .net and I am trying to create simple request submission form and keep getting an error: Could not access 'CDO.Message' object.

Any ideas?

Thanks.

bruce
07-29-2003, 03:10 AM
Try this code


<%@ Page Language="VB" %>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "you@yourdomainname.com"
mailMessage.To = "someone@somewhere.com"
mailMessage.Subject = "This is a sample mail sent from ASP.net Mail Component"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.body = "Congratulation" & VbCrLf & "If you receive this is, your mail component works"
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
lblMessage.text = "Mail Sent"
End Sub
</script>



[b]quote:Originally posted by dasp

Can you post your code?

</blockquote id="quote"></font id="quote">

Eric
07-29-2003, 09:34 AM
Can you post your code?

bruce
08-21-2003, 02:23 AM
You won't need that, that was a mistake.


[b]quote:Originally posted by steurm

I use practically the same code, but is in C#.
Any idea how to implement the "Handles MyBase.Load" in C# ?
thanks !


--
Steurm
www.steurm.net
</blockquote id="quote"></font id="quote">

steurm
08-21-2003, 06:03 AM
I use practically the same code, but is in C#.
Any idea how to implement the "Handles MyBase.Load" in C# ?
thanks !


--
Steurm
www.steurm.net

housetouror
08-30-2004, 03:58 AM
This component works great. But can anyone tell me why it sends two duplicate messages? Much thanks.

bruce
08-30-2004, 10:55 AM
Can you post the code?

[b]quote:Originally posted by housetouror

This component works great. But can anyone tell me why it sends two duplicate messages? Much thanks.



</blockquote id="quote"></font id="quote">

B.

DiscountASP.NET
http://www.DiscountASP.NET

housetouror
08-31-2004, 02:52 AM
Sure, I've added the email component as a sub procedure to alert me with an email ONLY when a new person registers (I'm using a cookie). I'm getting one blank email for when the page loads, then one for when the new info is entered. Thanks for your help

Sub AddNewFanEmail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FanEmail as String = txtEmailAddress.Text
If CheckFanEmailAddresses(FanEmail) = false Then
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "anyone@anywhere.net"
mailMessage.To = "scott.coulson@snet.net"
mailMessage.Subject = "This is an email"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.body = "The person's email is " & txtEmailAddress.text
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
End If

End Sub

Scott
08-31-2004, 06:40 AM
Not sure about this, but I'd bet that removing "Handles MyBase.Load" from your AddNewFanEmail method will solve the problem.

Where in your code are you calling AddNewFanEMail?

housetouror
09-01-2004, 01:22 AM
I got rid of the "Handles MyBase.Load" but it just disabled the component and I get no email sent. The Sub AddNewFanEmail was actually something I accidentally left while expiramenting. I changed it back to Private Sub Page_Load, but it makes absolutely no difference to the email component. Still get two messages.

The component code currently reads as follows:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FanEmail as String = txtEmailAddress.Text
If CheckFanEmailAddresses(FanEmail) = false Then
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "anyone@anywhere.net"
mailMessage.To = "scott@mapleleafmortgage.net"
mailMessage.Subject = "This is an email"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.body = "The person's email is " & txtEmailAddress.text
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
End If

End Sub

Thanks to you all.

rrhandle
09-21-2004, 03:36 AM
I am having a similar problem using CDO with ASP. I get 3 duplicate emails. Did you ever resolve this problem?

steurm
09-22-2004, 11:42 AM
Is it possible that the procedure is called in the page_load event ? I presume that the mail should be sent after clicking a button, so try to put the procedure after a
[quote]if(Page.IsPostback)
{
...
}</CODE>

--
Steurm
www.steurm.net/steurm