You can c reate a user control and add it to your main page

santhosh kumar replied to imran khan at 05-Jul-08 01:00
    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

Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  how to give use interface for creating body of mail - imran khan  05-Jul-08 12:02 12:02:39 AM
      use Rich text Editors for this... - Vasanthakumar D  05-Jul-08 12:12 12:12:34 AM
      See this - Sujit Patil  05-Jul-08 12:13 12:13:26 AM
      give use interface for creating body of mail - Swapnil Salunke  05-Jul-08 12:16 12:16:24 AM
      You can c reate a user control and add it to your main page - santhosh kumar  05-Jul-08 01:00 1:00:47 AM
      check here - santhosh kapa  05-Jul-08 01:43 1:43:48 AM
      Try this - sri sri  05-Jul-08 02:33 2:33:58 AM
View Posts