How to use Asp.net
  • Home
  • About us
  • Disclaimer
  • joy of helping
KEEP IN TOUCH

Send a web form as a Email asp.net vb.net

Mar27
2011
Leave a Comment Written by vikram

In this article I am sending Web form as E-mail. Whatever you placed on the form it will be send as a e-mail.

Firstly, create an account in Gmail and fill password and Id in mailAuthentication parameters. I m attaching a receipt images as an example which I have send as E-mail to clients after fetch the record from database.

Hope it will help you.

Imports System.Data

Imports System.IO

Imports System.Data.SqlClient

Partial Class default

Inherits System.Web.UI.Page

Private Sub webformasemail()  ‘call this method where u need

‘Declare the following variables

Dim objMM As New MailMessage()

Dim SB As New StringBuilder()

Dim SW As New StringWriter(SB)

Dim htmlTW As New HtmlTextWriter(SW)

Me.Page.RenderControl(htmlTW) ‘ it will render the default web form page

Dim webform As String = SB.ToString()

Try

Dim mail As New System.Net.Mail.MailMessage(“fromemailid”,”toemailid”, “Subject”,webform )

 

‘Proper Authentication Details need to be passed when sending email from gmail

Dim mailAuthentication As New System.Net.NetworkCredential(“ursid”, “urpassword”)

‘Smtp Mail server of Gmail is “smpt.gmail.com” and its port no. 587

Dim mailClient As New System.Net.Mail.SmtpClient(“smtp.gmail.com”, 587)

‘Enable SSL

‘Gmail is SSL certify so that why we need to set Enabelssl=true

mailClient.EnableSsl = True

mailClient.UseDefaultCredentials = False

mailClient.Credentials = mailAuthentication

 

mail.IsBodyHtml = True ‘ It will render the whole page before send the email

mailClient.Send(mail)

Catch ex As Exception

Labe1.text=” Unable to send the message”

End Try

response.redirect(“e_mailsent.aspx”)  ‘Or you can use the VerifyRenderingInServerForm to avoid Error.

End class

Public Overloads Overrides Sub VerifyRenderingInServerForm ByVal control As Control)

‘ Verifies that the control is rendered

End Sub

 

*Note: Error:

[Control 'XXXXXX' of type 'XXXXXX' must be placed inside a form tag with runat=server.]

to avoid above mentioned error use the [VerifyRenderingInServerForm] code.

 

With Regards

Vik

Posted in Asp.net
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« How to use Datalist paging in asp.net ADO.net way vb.net
» How to send E-mail in Asp.net Vb.net

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Joy of Helping

Any sort of help to the children who are fatherless, poor & are from far-off areas.
Joy of Helping

Facebook Link

Asp dot Net ,Ajax,Xml.

Recent Posts

  • ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • How to get second highest Salary sql server 2008
  • Insert values, insert into, insert default value, insert execute and select into sql server 2008
  • How to Bind GridView with SqlDataReader in Asp.net
  • how to attach files to email without storing on disk using Asp.net FileUpload control

Recent Comments

  • Anonymous on ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • dhananjay on How to use GridView with Insert, Edit, Update, Delete the Ado.net way C#
  • dev on How can we limit the characters in multiline textbox asp.net using JavaScript
  • navneet on How to display image in Image control after upload on the server asp.net C#
  • AnhVu on How to do Shopping Cart in Asp.net C#

Archives

  • February 2013
  • September 2012
  • April 2012
  • January 2012
  • October 2011
  • August 2011
  • May 2011
  • April 2011
  • March 2011

Categories

  • Asp.net
  • jQuery
  • Sql Server

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

EvoLve theme by Theme4Press  •  Powered by WordPress How to use Asp.net