TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • C#.NET
  • How to Send an Email using C#.NET?
C#.NET

How to Send an Email using C#.NET?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
0 1,437
Share

You see, When you create a desktop application, you need to build such a system which can send email. This is crucial because when the user register into your system, you need to get notified and it is also useful in case such as when your client forget their password, they can send request for the password through your system. This overcome the problem of opening browser and login to any email provider website and send email to you for their password.

Steps:

 

I am assuming that you have Visual Studio, Open your Visual Studio and click on File>new project, From the left side of your window, select Visual C#>Window and from the middle side select Windows Forms Application and then give the name of your project and then click OK which is shown in below.

2. From the ToolBox Drag and Drop four label, four Textbox and one button in your form and change the properties of these controls by selecting each control and right click that particular control and click on properties.(You can change the color of each control, increase the font of each control)

Four Label for Receiving email, sending email, password of sending email, Actual Mail Message
Four Textbox for Receiving email, sending email, password of sending email, Actual Mail Message
Button to send

NOTE: You can increase the message box large for this select message box textbox go to properties and then change the multiline to true and ScrollBars to Both and the expand this textbox by dragging it. And change the password Text Box property PasswordChar to any character so that you can hide your password.

How to send email using c#?
How to send email using c#?

3. Double click on Send button to go to the .cs section of your project and scroll up and then add the following namespace to your program as:

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

4. Write the following piece of code inside the clicking event of Login Button:


string to, from, pass, mail;
to = (txtReceiver.Text).ToString();
from = (txtSender.Text).ToString();
mail = (txtMail.Text).ToString();
pass = (txtPassword.Text).ToString();
MailMessage message = new MailMessage();
message.To.Add(to);
message.From = new MailAddress(from);
message.Body = mail;
message.Subject = "Email Testing";
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(from, pass);
try
{
smtp.Send(message);
MessageBox.Show("Email send successfully", "Email", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}

5. Run your project by clicking in that play button. Input your credentials of gmail enter the phone number in which you want to send SMS and type your Message in respective textbox and then click on Send button. That’s it.

 

if you have any confusion, you can watch the following video:

 

Continue Reading
c# code to send emailc# email codec# email sending applicationc# mailc# mail functionc# send emailc# send email smtpHow do I send C# mail via SMTPhow do i send email using c#how to send email from c# using smtp authenticationhow to send email using c# application using gmailmail transfer system in c#ran bahadur bkRanBKsend email using c#send mailSend mail using c# via SMTPsend mail using smtp in c# exampleTechSupportNep
0 1,437
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to Create Multi User Login Apps in Android?

Next Post

How to Create User Registration Form in C#.NET Using SQL Server Database?

You might also like More from author
C#.NET

How to Send Free SMS Using C#.NET? [With Source Code]

C#.NET

How to Create Login Window in C# using SQL Server Database in Visual Studio?

Leave a comment
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.