Asp.net Send Email By Using Your Gmail Account


sending email in asp.net

In previous article I explained How to Send Multiple Emails by Using Gmail Account. Now i show How to Send Email by Using Gmail ID in ASP.NET by using C# Coding and Resolve a SMTP Server Secure Connection and Authentication 5.5.1 Required Error | The SMTP Server Requires a Secure Connection or the Client was not authenticated.

In this articles, i'm going to explain how to send email in asp.net, for sending email we use two class's i.e MailMessage Class and SMTPClient Class these two Class are predefined class from this namespaces (System.Net.Mail Namespace).

HTML Markup : Create Sending Email Page

 <div>
     <table>
      <tr>
      <td>
       <table>
      <tr>
       <th colspan="2" align="left">Single Mail Sending</th>
      </tr>
      <tr>
      <td style="width:20px;">To : </td><td><asp:TextBox ID="txt_single_mail" runat="server" Width="310px"></asp:TextBox></td>
      </tr>
      <tr>
      <td colspan="2">
       <asp:TextBox ID="txt_single_msg" runat="server" TextMode="MultiLine" Width="336px" 
              Height="199px"></asp:TextBox>
      </td>
      </tr>
      <tr>
       <td colspan="2">
        <asp:Button ID="Btn_single_mail" runat="server" Text="Send Single Mail" 
               onclick="Btn_single_mail_Click" />
       </td>
      </tr>
     </table>
      </td>
      </tr>
      </table>
      </div>

C# Coding

C# Coding :Sending Email Code

protected void Btn_single_mail_Click(object sender, EventArgs e)
    {
        MailMessage ms = new MailMessage("your Gmail ID", txt_single_mail.Text);
        ms.Subject = "Testing Sending Single Mail";
        ms.Body = txt_single_msg.Text;
        ms.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
        smtp.Credentials = new System.Net.NetworkCredential("your Gmail ID", "your Gmail ID Password");
        smtp.EnableSsl = true;
        smtp.Send(ms);
    }

Next Tutorials : How to Resove SMTPException




The SMTP SEVER Requires Secure Connection or the Client was not Authenticated the Server Response was 5.5.1 Authentication Required
0 Komentar untuk "Asp.net Send Email By Using Your Gmail Account"

Back To Top