Hi,
Create a User Control whose page source is:-
<%@ Control Language="VB" EnableViewState="False" Debug="true" Strict="false" %>
<%@ 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 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 = "salman.zafar@xyz.com"
mail.To = request.form("EmailAddress")
mail.Subject = "asp.net user controls"
mail.Body = "mail sent using asp.net user controls"
mail.BodyFormat = MailFormat.Html
' Mail Server Internet Address
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","mail.xyz.com")
' MailServerPort Number (Default 25 - which is SMTP 25/TCP)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25")
' There are two levels of Send Usage
' cdoSendUsingPickup = 1 "Send message using the local SMTP service pickup directory."
' cdoSendUsingPort = 2 "Send the message using the network (SMTP over the network)."
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "1")
' There are three levels of SMTP Authentication
' cdoAnonymous = 0 "Do not authenticate"
' cdoBasic = 1 "Use basic (clear-text) authentication."
' cdoNTLM = 2 "Use NTLM authentication"
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
' User account and password to authenticate to the server defined above
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "YourUserName")
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "YourPassword")
SmtpMail.SmtpServer = "mail.xyz.com"
SmtpMail.Send(mail)
End If
End Sub
</SCRIPT>
<asp:Label id="lblMessage" runat="server" BorderColor="#cccccc" BorderStyle="solid" Width="448px"
Font-Name="Verdana"></asp:Label>
<FORM name="form1" method="post" runat="server" ID="Form1">
Email Address:<INPUT style="BACKGROUND-COLOR: #ffffa0" size="30" name="EmailAddress">
<INPUT id="btnSubmit" type="submit" value="Sending Email " name="b1" runat="server" OnServerClick="btn_Click">
</FORM>
Drag above control in any aspx file and start using emailing with predefined text in ascx file.
The HTML code for emailStaticTest.aspx looks like this
<%@ Register TagPrefix="uc1" TagName="emailStatic" Src="emailStatic.ascx" %>
<%@
Page language="c#" Codebehind="emailStaticTest.aspx.cs"
AutoEventWireup="false"
Inherits="CustomControls.emailStatic.emailStaticTest" %>
<uc1:emailStatic id="EmailStatic1" runat="server"></uc1:emailStatic>
Regards,
Santhosh |