Dear frnds i am new to this and please help me grow and gain knowledge on asp.net

i want to know how to send contact form to gmail i wanted code please do the need full i wanted code in C# asp.net

Dani AI

Generated

A short, practical summary for (and a reality check for / ): the contact form should post to your server, and the server sends mail through an SMTP server (Gmail or a transactional provider). For Gmail the outgoing host is smtp.gmail.com — prefer port 587 with STARTTLS (465 can be used for SSL). Google now requires stronger auth: either enable 2‑Step Verification and create an App Password for simple SMTP, or implement OAuth2 for SMTP access. (developers.google.com)

A minimal, testable C# snippet (works for .NET Framework when you use an App Password):

using System.Net;
using System.Net.Mail;

var msg = new MailMessage("you@gmail.com", "recipient@example.com")
{
    Subject = "Contact form",
    Body = "Message from contact form",
    IsBodyHtml = true
};

using (var smtp = new SmtpClient("smtp.gmail.com", 587))
{
    smtp.EnableSsl = true;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new NetworkCredential("you@gmail.com", "YOUR_APP_PASSWORD");
    smtp.Send(msg);
}

Use this for local testing or small sites; it follows the System.Net.Mail API. For reference on the API and Send behavior see Microsoft docs. (learn.microsoft.com)

For production or anything running on modern .NET, prefer MailKit + OAuth2 (MailKit supports XOAUTH2 and is the recommended library for OAuth flows). If your app sends lots of mail, consider an email API provider (SendGrid, Mailgun, etc.) to avoid deliverability and auth headaches. (github.com)

Quick troubleshooting checklist (common causes):

  • Wrong port/TLS combo — try 587 + STARTTLS. (developers.google.com)
  • If auth fails, enable 2‑Step Verification and use an App Password, or implement OAuth2. ()
  • Check firewall/hosting provider for blocked outbound SMTP and inspect the exception stack (connect → auth → send).

This gives a runnable example plus the secure, long‑term options.

Recommended Answers

All 2 Replies

Atleast do some search and explore by yourself in google and try to understand the problem, then if you will have problem we will help you here. Just giving the code straigt away will not help you anyway.

i have done work on same problem. i have solved it
.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.