Home

Thursday, 14 July 2016

Send Mail Using C# Asp.net

Step 1) Write below code in Button Click and get data and assign it property of Mail-message-

protected void Page_Load(object sender, EventArgs e)
        {
            MailMessage mailAddress = new MailMessage("x@gmail.com", "y@gmail.com");
            mailAddress.Subject = "Testing Email";
            mailAddress.Body = "Hello";
             SmtpClient smtp = new SmtpClient();
           smtp.Send(mailAddress);
    }

Where x@gmail.com is Sender Mail address and y@gmail.com is Recipient mail address


Step 2)Add Below code in web.config file-
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" port="587" userName="x@gmail.com" password="fgfgfgag" enableSsl="true"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

No comments:

Post a Comment