Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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
  #1 (permalink)  
Old February 3rd, 2009, 06:59 AM
Authorized User
 
Join Date: Dec 2007
Location: hyderabad, Andhra Pradesh, India.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default sending webpage as an email

Hi to all
I am sending a web page through mail. For this I coded like below
ProtectedSub btnMail_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnMail.Click
Dim message AsString = readHtmlPage(Server.MapPath("repQuotation.aspx"))
If Page.IsValid Then
Trace.Write("submit", "Page is valid -- send email.")
Try
Dim mailFrom As MailAddress = New MailAddress("wecare@sixthsense.in")
Dim mailTo As MailAddress = New MailAddress("shanwaj_begum@yahoo.com")
Dim mailer As MailMessage = New MailMessage(mailFrom, mailTo)
mailer.Subject =
"Sixthsense Quotation".Trim
mailer.Body = message
mailer.IsBodyHtml =
True
Dim smtpMail As SmtpClient = New SmtpClient
smtpMail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
smtpMail.Send(mailer)
lblmsg.Text =
"page sent"
Catch ex As Exception
EndTry
EndIf
EndSub


Protected Function readHtmlPage(ByVal url As String) As String
Dim result As String
Dim objResponse As webresponse
Dim objrequest As WebRequest
objrequest = System.Net.HttpWebRequest.Create(url)
objResponse = objrequest.GetResponse
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream)
Using sr
result = sr.ReadToEnd
sr.Close()
End Using
Return result
End Function

Here mail is sending successfully,but datagrid and dynamic values are not displaying.Mail is showing "<%@ Page Language="VB" AutoEventWireup="false" CodeFile="repQuotation.aspx">" this tag.I dont want to display it.how can i do it.
Please any body can help me to how to send a webpage through mail.
__________________
shanwaj
  #2 (permalink)  
Old February 3rd, 2009, 02:18 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You have the right idea. Your problem is here:

Code:
Dim message AsString = readHtmlPage(Server.MapPath("repQuotation.aspx"))
Server.MapPath returns a physical path, not a Uri. The HttpWebRequest.Create() method expects a string which points to a Uri -- in other words, a virtual path, not a physical one.

You can test this by passing in any known good URL into your readHtmlPage method:

Code:
Dim message AsString = readHtmlPage("http://www.google.com")
This will email you Google's home page.

The other thing to keep in mind that when you email a web page, any links, images, or other resources referenced by relative URLs won't work. Resources have to point to absolute URLs in order to be functional, just as in any external HTML document.

Given that, you probably need to scan the response stream for relative URLs and process them accordingly.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #3 (permalink)  
Old February 4th, 2009, 01:43 AM
Authorized User
 
Join Date: Dec 2007
Location: hyderabad, Andhra Pradesh, India.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Lee
Thanks for your reply.Just now I followed your suggestion. I sent google home page.It has sent successfully but the image is not displayed. Here url is containting dynamic values like
" http://www.sixthcense.com/repQuotation.aspx?cp=&Id=5 "
how can i pass above the above link.Here id number will change by selecting quotation list.Please help me how can i send a url with dynamic values.

Thanks in advance.
__________________
shanwaj
  #4 (permalink)  
Old February 4th, 2009, 01:50 AM
Authorized User
 
Join Date: Dec 2007
Location: hyderabad, Andhra Pradesh, India.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Lee
I successed in sending webpage as mail with dynamic values. I changed some line in code like below
Code:
ProtectedSub btnMailMe_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnMailMe.Click
'Dim message As String = readHtmlPage("http://www.sixthcense.com/repQuotation.aspx?cp=&Id=5")
Dim message AsString = readHtmlPage("http://www.sixthcense.com/repQuotation.aspx?cp=" & cpn() & "&Id=" & vid())
If Page.IsValid Then
Trace.Write("submit", "Page is valid -- send email.")
Try
Dim mailFrom As MailAddress = New MailAddress("shanwajbegum@gmail.com")
Dim mailTo As MailAddress = New MailAddress("shanwaj_begum@yahoo.com")
Dim mailer As MailMessage = New MailMessage(mailFrom, mailTo)
mailer.Subject = "Sending a webpage as a mail body".Trim
mailer.Body = message
mailer.IsBodyHtml = True
Dim smtpMail As SmtpClient = New SmtpClient
smtpMail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
smtpMail.Send(mailer)
lblmsg.Text = "page sent"
Catch ex As Exception
EndTry
EndIf
EndSub
EndClass
Really I appreciate p2p services and all our respected p2p users helping nature like u.
Thank you very much.
__________________
shanwaj
  #5 (permalink)  
Old February 4th, 2009, 12:41 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by shanwaj View Post
Hi Lee
Thanks for your reply.Just now I followed your suggestion. I sent google home page.It has sent successfully but the image is not displayed.
Yes, as I pointed out, resources (like images) that use relative URLs in their HTML markup won't work. That would apply to images and links on most web pages.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #6 (permalink)  
Old March 20th, 2009, 08:55 AM
Authorized User
 
Join Date: Dec 2007
Location: hyderabad, Andhra Pradesh, India.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi to all,
Congratulations to all prize winners of previous month. I am getting a new problem while sending a web page by email. The issue is that whenever i send a mail, i'm always getting the Login page via email.I feel that if i request for "http://testsite/home.aspx?id=1" it gets redirected to "http://testsite/login.aspx" since due to some session issue.I;m checking the session in a page base class associated with each page.
Can anyone have any other alternative for the same that If i send a page via email.Please give your valuble help to me that.

Thanks in advance

shanwaj
__________________
shanwaj
  #7 (permalink)  
Old March 20th, 2009, 09:53 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Are you trying to send a secured page?
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
shanwaj (March 21st, 2009)
  #8 (permalink)  
Old March 21st, 2009, 12:13 AM
Authorized User
 
Join Date: Dec 2007
Location: hyderabad, Andhra Pradesh, India.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

hi,
Thanks for your quick response.Sorry for my late reply,yesterday my duty hours was over.So I could not reply you.
Yes Mr.Lee , I am sending a secured page. Whenever I am sending email its getting login page.Please help me.
__________________
shanwaj
  #9 (permalink)  
Old March 21st, 2009, 10:38 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

When you issue an unauthenticated request for an secured page, it redirects to the login page.

You need to authenticate the request in your ReadHtmlPage method. Because the request you are creating is unauthenticated, the response from it is being redirected to the login page.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #10 (permalink)  
Old April 11th, 2009, 11:19 AM
Registered User
 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi there Mr Dumond,

My question is regarding the below code;

I'm trying to do something similar to what's there in the code but the difference is the url of the page I'm sending changes as there is a value passed from the previous page altering the content of each new page.

How could i pass the correct url to be mailed??

Dim message AsString = readHtmlPage("http://localhost:3523/ATM-REPORTING/Sups_comp_1nd.aspx?ENTRY_ID=11")

The value of the ENTRY_ID changes with the users selection on the privous page.

would really appreciate your help.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending email maitias C# 2005 2 February 17th, 2006 11:24 AM
Sending an email that looks like a webpage. rayncarnation ASP.NET 1.0 and 1.1 Basics 0 October 11th, 2005 09:17 AM
sending email keyvanjan Classic ASP Components 1 May 9th, 2005 05:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.