How to send email in .NET

harsh123

harsh123

Posted on May 8, 2022

How to send email in .NET

Email.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace email_sending
{
    public partial class email : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void send_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient smpt = new SmtpClient();
                message.From = new MailAddress("Enter Your Email Here");
                message.To.Add(new MailAddress(to.Text));
                message.Subject = "Testing";
                message.IsBodyHtml = true;
                message.Body = body.Text;
                smpt.Port = 587;
                smpt.Host = "smtp.office365.com";
                smpt.EnableSsl = true;
                smpt.UseDefaultCredentials = false;
                smpt.Credentials = new NetworkCredential("Enter Your Email Here", "Enter Your Passwrod");
                smpt.DeliveryMethod = SmtpDeliveryMethod.Network;
                smpt.Send(message);
            } catch (Exception ex)
            {

            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Folder Structure

Image description

Image description

Read More

πŸ’– πŸ’ͺ πŸ™… 🚩
harsh123
harsh123

Posted on May 8, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related