Author Topic: Asp.Net Source Code - Send Email using ASP.NET formatted in HTML  (Read 2554 times)


  • Winners @ IT Acumens
  • Co Admin
  • Hero Member
  • *****
  • Posts: 10216
  • Am @ IT Acumens
    • View Profile
    • IT Acumens Bala
Send Email using ASP.NET formatted in HTML

<%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="False" Strict="True" %><%@ Import Namespace="System.Web.Mail" %>
<SCRIPT language=VB runat="server">
Sub Page_load(Sender as Object, E as EventArgs)

If request.form("EmailAddress") = "" Then
dim strResponse as string = "<h2>Send Email using ASP.NET formatted in HTML</h2>"
lblMessage.Text = strResponse
dim strResponse as string = "You just sent an email message formatted in HTML to:
<h2>" & request("EmailAddress") & "</h2>"
lblMessage.Text = strResponse
End If

End Sub

Sub btn_Click(sender as Object, e as System.EventArgs)

If request.form("EmailAddress") <> ""
Dim mail As New MailMessage
mail.From = ""
mail.To = request.form("EmailAddress")
mail.Subject = "Message sent using ASP.NET and CDONTS"
mail.Body = "HTML Message sent from using ASP.NET and Cdonts
<a href='http : // . aspx'>Wonder how this is done?[/url]

<a href='http : // /setupcdonts . aspx'>Wonder How to setup CDONTS?[/url]"
mail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "LocalServerName"
End If
End Sub


<H1 align=center>Sending Email via ASP.NET and CDONTS..</H1><B><A
href="/ aspnet/setupcdonts . aspx">How do I setup my server to use CDONTS?[/url]</B>

<A href="/ allzips/ emaildotnet . zip"><IMG
src="http : / / /downloadcode  . gif" border=0>[/url]

<asp:Label id=lblMessage runat="server" BorderColor="#cccccc"
BorderStyle="solid" Width="400px" Font-Name="Verdana"></asp:Label>
<FORM name=form1 method=post runat="server">Email Address:<INPUT
style="BACKGROUND-COLOR: #ffffa0" size=30 name=EmailAddress>

<INPUT id=btnSubmit type=submit value="Sending Email with ASP.NET" name=b1 runat="server" OnServerClick="btn_Click">

Create new password digests in the WEB.CONFIG file dynamically at runtime

Imports System.Text
Imports System.Web.Security
Imports System.Xml

Public Class AddUsers
Inherits System.Web.UI.Page

Protected WithEvents btnCreate As System.Web.UI.WebControls.Button
Protected WithEvents txtPassword As System.Web.UI.HtmlControls.HtmlInputText
Protected WithEvents txtUsername As System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub btnCreate_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnCreate.Click

Dim strPlainText As String = txtPassword.Value
Dim strUsername As String = txtUsername.Text

If strPlainText <> "" And strUsername <> "" Then
Dim strHash As String = _
FormsAuthentication.HashPasswordForStoringInConfigFile( _
strPlainText, _

strPlainText = ""

'Open config file and build new password digest
Dim doc As New XmlDocument()


Dim newElement As XmlElement = doc.CreateElement("user")

Dim attribName As XmlAttribute = doc.CreateAttribute("name")
attribName.Value = strUsername

Dim attribPassword As XmlAttribute = doc.CreateAttribute("password")
attribPassword.Value = strHash


Dim credentials As XmlElement = doc.GetElementsByTagName("credentials").Item(0)



lblResults.Text = "User saved. Username:" & _
strUsername & " Password:" & strHash

lblResults.Visible = True

txtPassword.Value = ""
txtUsername.Text = ""
End If

End Sub
End Class