Here is code 
1) Create one Visual studio project name as SendmailApplication .
2) open you default.aspx (designer page). and write down below code
1) Create one Visual studio project name as SendmailApplication .
2) open you default.aspx (designer page). and write down below code
Default.aspx page:
 ================================================================
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Label ID ="Sender" runat="server" AssociatedControlID="txtSender" Text="From :" Width="600"></asp:Label>
      <asp:TextBox ID="txtSender" runat ="server" Width="200px" 
            style="position: relative; top: 0px; left: 90px" ></asp:TextBox><br />
      <br />
      <asp:Label ID="receiver" runat="server" AssociatedControlID="txtreceiver" Text="To :"></asp:Label>
      <asp:TextBox ID ="txtreceiver" runat="server" 
            style="position: relative; top: 0px; left: 110px; width: 214px"></asp:TextBox><br />
       <br />
      <asp:Label ID="subject" runat="server" AssociatedControlID="txtsubject" Text="Subject :"></asp:Label>
                  style="position: relative; top: 0px; left: 70px; width: 484px;"></asp:TextBox><br />
       <br />
       <asp:Label ID="msgbody" runat="server" AssociatedControlID="txtmsgbody" 
            Text="Body :" style="position: relative"></asp:Label>
      <asp:TextBox ID ="txtmsgbody" runat="server" Height="93px" TextMode="MultiLine" 
            style="position: relative; top: 0px; left: 80px; width: 484px"></asp:TextBox><br />
             <br />
      <asp:Button ID="btnsend" runat="server" Text="Send" onclick="btnsend_Click" 
            style="position: relative; top: 0px; left: 450px" />
     
    </div>
    </form>
</body>
</html>
=========================================================================Use following Namespaces  to send mail 
         Using System.Net;
         Using System.Net.Mail;
create message format and body.
                       paramenter  - Sender and receiver ( from,To)
Assign body and subject to mailmessage instance .
Create instance of SmtpClient assign host - smtp.gmail.com
    and port - 587 Provide credential of your domain and send mail .& paste below code on click event of button.
Default.aspx.cs page : ===========================================================================protected void btnsend_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage(new MailAddress(txtSender.Text), new MailAddress(txtreceiver.Text));
                mail.Subject = txtsubject.Text;
                mail.Body = txtmsgbody.Text;
                SmtpClient client = new SmtpClient();
                client.Host = "smtp.gmail.com";
                client.Port = 587;
                client.Credentials = new NetworkCredential("abc@gmail.com", "pwd***");
                client.EnableSsl = true;
                client.Send(mail);
            }
            catch (Exception ex)
            {
            }
        }====================================================================================== 
Hope this will help you........
Regards,Gajanan
Comments
Post a Comment