 |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
 | This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

November 8th, 2007, 05:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
There are at least two things wrong:
First, you are confusing yourself with variable names. For example:
Dim mySmtpClient As New System.Net.Mail.MailMessage
Why do you call it mySmtpClient while it isn't a SmtpClient but a MailMessage?
Secondly, what do you think you need this object for? What are you doing with it? From what I can tell, not much. You still pass simple variables to the Send method instead of the actual MailMessage object:
Dim myMailMessage As New System.Net.Mail.MailMessage
myMailMessage.IsBodyHtml = True
...
' Some code here to assign things like the Subject and body to the message
Dim myClient As New System.Net.Mail.SmtpClient
myClient.Host = "itascsrv01"
myClient.Send(myMailMessage)
I think you may need to brush up your .NET knowledge a little. Much of this is basic .NET coding, and IMO, most of it can be figured out simply by looking at IntelliSense, see what it offers, what it expects you to pass in and so on.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

November 8th, 2007, 08:51 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well i am relative new to .net
i can right for a short time now in asp but not expert.
But i want to step on into .net instead of asp
and my asp start was a webshop so i wanted to change it in a .net webshop.
But your right my .net is really basic.
(i am going to improve this but the Webshop is kind of urgent.)
I've tried to set breakpoints:
He hits the isbodyhtml = true so that aint the problem the thing is (i think) the isbodyhtml is set on a diffrent piece of code.
But i want to thank you for all your help ill try to find it out myself becouse you allready did more then enough ;)
|
|

November 8th, 2007, 09:31 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I didn't say .NET is basic; I said that the stuff with variables etc is basic within .NET
How does your code look like now?
And don't worry about being new and asking questions; that's what these forums are for.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

November 8th, 2007, 09:40 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I now have the following code.
Quote:
|
quote:Dim MyMailMessage As New System.Net.Mail.MailMessage
|
Quote:
MyMailMessage.IsBodyHtml = True
theMessage = theMessage.Replace("##ShoppingCart##", _
GetHtmlFromControl(myGridView))
theMessage = theMessage.Replace("##OrderNumber##", orderId.ToString())
Dim myClient As New System.Net.Mail.SmtpClient
myClient.Host = "itascsrv01"
myClient.Send("[email protected]", emailAddress, theSubject, theMessage)
|
this doesn't give any errors and sends out the mail
but not in html
(though if i hit the following line with a breakpoint:
MyMailMessage.IsBodyHtml = True
he shows me the line. I've tried multiple scripts but it all has its downsides all the time it says i cant use names and they don't excists :S.)
EDIT:
I also want to CC the same message to 3 people also the cc funtion i can;t get to work it says it's the wrong type.
|
|

November 8th, 2007, 11:15 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Looks like we're stuck in a loop. Did you see the code I posted in my previous message? You keep sending plain stuff in the Send method. Look at my code again and see I send the MailMessage object, not a separate To address, Subject, body and so on.
So basically, you need your code to this:
1. Instantiate a MailMessage
2. Set stuff like To, From, Subject and Body
3. Set IsBodyHtml = True
4. Send the message by using the Send method and pass in the MailMessage instance, not separate parameters.
I can't make it any easier than this. My last example shows you how to do it. If that's not enough, Google a bit for more information and complete examples.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

November 8th, 2007, 11:20 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Jeah i know you said that
To, From, Subject and Body
But To is a variable
Body is a variable
Subject i declared above the code
But i am now going to try it like how you say it.
here is the body and subject:
Dim theSubject As String = "Je bestelling bij Itasc"
Dim theMessage As String = My.Computer.FileSystem.ReadAllText _
(AppConfiguration.ConfirmationMessageLocation)
|
|

November 8th, 2007, 11:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Heuh?? Not sure what you are asking. What do you mean with "To is a variable"? It's a property of the MailMessage class. You need to use its Add method to add an address.
Why don't look at my code, adapt your to it, and then post the full code. It's about the Send method, not something else that's important here. Or take a look here: http://aspnet.4guysfromrolla.com/articles/072606-1.aspx
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

November 8th, 2007, 11:45 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Wait i'll say whats going on:
1st: I can send an email with everything in it, it is just not formatted in html.
Then you said i should use the code:
Quote:
|
quote:Dim myMailMessage As New System.Net.Mail.MailMessage
|
Quote:
myMailMessage.IsBodyHtml = True
...
' Some code here to assign things like the Subject and body to the message
Dim myClient As New System.Net.Mail.SmtpClient
myClient.Host = "itascsrv01"
myClient.Send(myMailMessage)
|
But how can i assign the subject and body etc if this is my code above the class:
Quote:
Dim myGridView As GridView = CreateGridView()
myGridView.DataSource = theShoppingCart.Items
myGridView.DataBind()
If myGridView.Rows.Count > 0 Then
myGridView.FooterRow.Cells(0).Text = "Totaal:"
myGridView.FooterRow.Cells(3).Text = _
String.Format("{0:c}", theShoppingCart.Total)
Dim theSubject As String = "Je bestelling bij Itasc"
Dim theMessage As String = My.Computer.FileSystem.ReadAllText _
(AppConfiguration.ConfirmationMessageLocation)
|
And then
if i do this:
Quote:
|
quote:Dim myMailMessage As New System.Net.Mail.MailMessage
|
Quote:
myMailMessage.IsBodyHtml = True
''''Examaple:
myMailMessage.To("[email protected]")
...
' Some code here to assign things like the Subject and body to the message
Dim myClient As New System.Net.Mail.SmtpClient
myClient.Host = "itascsrv01"
myClient.Send(myMailMessage)
|
i get the following error:
1. Property access must assign to the property or use its value.
I thought i could just change the original code so that it would format it in html ;)
But i am going to check the 4 guys from rolla page.
EDIT:
ive check the 4guys page and tried this:
Quote:
|
quote: '(1) Create the MailMessage instance
|
Quote:
Dim mm As New MailMessage("[email protected]", "[email protected]")
'(2) Assign the MailMessage's properties
mm.Subject = "HTML-Formatted Email Demo Using the IsBodyHtml Property"
mm.Body = "<h2>This is an HTML-Formatted Email Send Using the <code>IsBodyHtml</code> Property</h2><p>Isn't HTML <em>neat</em>?</p><p>You can make all sorts of <span style=""color:red;font-weight:bold;"">pretty colors!!</span>.</p>"
mm.IsBodyHtml = True
'(3) Create the SmtpClient object
Dim smtp As New SmtpClient
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
|
This works okej
But my question is
how do i make the:
to: a variable (because its diffrent for every customer)
body: a variable (this needs to show the gridview en ordernumber)
That is my big question ;)
|
|

November 8th, 2007, 12:00 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
The To property is a collection so you need to call its Add method:
myMessage.To.Add(new MailAddress(Address, Name)
The From is also a strongly typed object:
myMessage.From = New MailAddress(Address, Name)
I'll try to post a better example later but this should be enough to get you a step further. You can also use this to Google or search elsewhere a bit further.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

November 9th, 2007, 04:09 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I got it working
only working on bcc'ing to more people but i can find this on google i think
anyway thanks for your help.
ill check things around here maybe that i can help people with somethings i figured out.
|
|
 |