Thursday, 16 May 2013

How to send email in asp.net

<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>

coding on Button1 click event

using System.Net.Mail;
 protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage Msg = new MailMessage();
        // Sender e-mail address.
        Msg.From = new MailAddress("shashinamdev786@gmail.com");

        // Recipient e-mail address.
      
        Msg.To.Add("yashwantnama@gmail.com");
        Msg.Subject = "email sending testing";
        Msg.Body = "hi i am sending u a mail ";
                // your remote SMTP server IP.
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.Credentials = new System.Net.NetworkCredential("sender_email_id", "password");
        smtp.EnableSsl = true;
        smtp.Send(Msg);
        Msg = null;
        Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...')</script>");
      

    }

No comments:

Post a Comment