Emailing rows of text into an E-mail body.

Discussion in 'Microsoft Dot NET' started by Guest, Feb 1, 2007.

  1. Guest

    Guest Guest

    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
     
    Guest, Feb 1, 2007
    #1
    1. Advertisements

  2. 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/articles/102203-1.2.aspx


    Hope this helps.

    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Feb 2, 2007
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    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/articles/102203-1.2.aspx
    >
    >
    > Hope this helps.
    >
    > Sincerely,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
     
    Guest, Feb 2, 2007
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sparky

    Emailing using MAPISendMail call

    Sparky, Jul 2, 2003, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    1,560
    dave wanta
    Jul 3, 2003
  2. Victor J. Servin

    Emailing with VB .Net

    Victor J. Servin, Aug 29, 2003, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    161
    Victor J. Servin
    Aug 29, 2003
  3. helpful sql

    convert columns to rows and rows to columns

    helpful sql, May 19, 2005, in forum: Microsoft Dot NET
    Replies:
    3
    Views:
    349
    helpful sql
    May 19, 2005
  4. Lee Zeitz

    Reading text-only body from MSMQ in C#

    Lee Zeitz, Oct 10, 2005, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    302
    Guest
    Oct 11, 2005
  5. Guest
    Replies:
    1
    Views:
    217
    RobinS
    Feb 23, 2007
Loading...

Share This Page