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

ganeshbala

  • Winners @ IT Acumens
  • Co Admin
  • Hero Member
  • *****
  • Posts: 10204
  • 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
Else
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 = "youraddress@domain.com"
mail.To = request.form("EmailAddress")
mail.Subject = "Message sent using ASP.NET and CDONTS"
mail.Body = "HTML Message sent from ASPFree.com using ASP.NET and Cdonts
<a href='http : // aspfree.com/aspnet/email . aspx'>Wonder how this is done?[/url]

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

</SCRIPT>

<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 : / /aspfree.com/images /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">
</FORM>


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.
InitializeComponent()
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, _
"sha1")

strPlainText = ""

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

doc.Load(Server.MapPath("..\Web.config"))

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

newElement.Attributes.Append(attribName)
newElement.Attributes.Append(attribPassword)

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

credentials.AppendChild(newElement)

doc.Save(Server.MapPath("../Web.config"))

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

lblResults.Visible = True

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

End Sub
End Class