473,480 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Emailing rows of text into an E-mail body.

To all,

I was wondering if someone has sample VB.NET code that will help me send
rows of a gridview into a body section of an e-mail. My goal is to present
multiple rows within a gridview to a table like format within an e-mail
message.

Thanks for any help,
Michael
Feb 1 '07 #1
2 1868
Hi Michael,

Short answer:

1) Create following class:

Public Class EmailReadyPage
Inherits System.Web.UI.Page

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
'DO NOTHING
End Sub
End Class

2) Inherit your WebForm from above class.

3) In server-side code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sb As New StringBuilder
Dim sw As New IO.StringWriter(sb)
Dim writer As New HtmlTextWriter(sw)
GridView1.RenderControl(writer)

Dim mail As New Net.Mail.MailMessage

mail.From = New Net.Mail.MailAddress(...)
mail.To.Add(...)
mail.Subject = "This is the GridView's output"

mail.IsBodyHtml = True
mail.Body = sb.ToString()

Dim smtp As New Net.Mail.SmtpClient(...)
' set smtp.Credentials if necessary
smtp.Send(mail)
End Sub
Long answer:

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code
http://aspnet.4guysfromrolla.com/articles/102203-1.aspx

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code, Part 2
http://aspnet.4guysfromrolla.com/art...02203-1.2.aspx
Hope this helps.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 2 '07 #2
Walter,

This looks like it will definitely work! Thank you so much!

Michael

"Walter Wang [MSFT]" wrote:
Hi Michael,

Short answer:

1) Create following class:

Public Class EmailReadyPage
Inherits System.Web.UI.Page

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
'DO NOTHING
End Sub
End Class

2) Inherit your WebForm from above class.

3) In server-side code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sb As New StringBuilder
Dim sw As New IO.StringWriter(sb)
Dim writer As New HtmlTextWriter(sw)
GridView1.RenderControl(writer)

Dim mail As New Net.Mail.MailMessage

mail.From = New Net.Mail.MailAddress(...)
mail.To.Add(...)
mail.Subject = "This is the GridView's output"

mail.IsBodyHtml = True
mail.Body = sb.ToString()

Dim smtp As New Net.Mail.SmtpClient(...)
' set smtp.Credentials if necessary
smtp.Send(mail)
End Sub
Long answer:

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code
http://aspnet.4guysfromrolla.com/articles/102203-1.aspx

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code, Part 2
http://aspnet.4guysfromrolla.com/art...02203-1.2.aspx
Hope this helps.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1763
by: Stanley Cheung | last post by:
Hi all, I am developing the application for send emailing list, actually, i can perform to send a email 1 by 1 and do it on aspx page. I have a enquiry that how can the application change to...
4
1630
by: Mike Moore | last post by:
What is the best way to launch outlook from an asp.net web page? Can you do this using MAPI or is there a control that you can purchase? We are unable to use SMTP. We use MS Exhange and MAPI...
0
1060
by: Mike Grace | last post by:
Hi, I am writing a web site which sends order confirmations to users via email. Two changes that are needed are as follows: 1) PDF files are going to be attached to the email. It could be...
7
1563
by: cover | last post by:
I have a form that writes to an MySQL database just fine but would like to email people to give them a heads up that an entry was made under their name (1 of 6 names on writing to the database). ...
11
7993
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
2
2215
by: Tim Hunter | last post by:
I have two questions regarding emailing from Access. My first question relates to how many email addresses is too much. I have a client who wants to email 1500 people at once. Is this possible or...
4
1834
by: Ron | last post by:
I have this code on one of my forms, the code takes whatever is in textboxes and adds it to a MS Access Database. It then shows a message that the operation was completed. Is there a universal...
1
1249
by: Momo15 | last post by:
When I try exporting a report in Rich Text Format or Email it, some my data is altered. Additionally, when I try “emailing” the same thing happens. One of my reports with was landscape orientation...
0
1947
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: ...
1
2037
by: bgernon | last post by:
I have a table that consists of two rows with three cells each row. The cells contain textboxes. I am able to successfully add a new row with textboxes when a button is clicked. The problem is...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.