Click here to Skip to main content
11,928,569 members (54,180 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


11 bookmarked

How to Create a Simple Email Sending Software Using C# Windows Forms

, 10 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
How to Send SMTP Email from your Computer to Webmail using C#


This is an SMTP (Simple Mail Transfer Protocol) client based application. This project describes an approach to sending email message from your desktop computer to webmail with or without attachment.

In order to implement SMTP client, I am using two namespaces as given below. In addition to sending message from local computer, I am using “” as a host server and 587 as host server port no.

To create this software first go to your IDE (Integrated Development Environment) Visual Studio then select C# and go to Windows Forms Application.

Project screenshot:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

namespace Email_Sanding_Softwares
    public partial class Form1 : Form
        public Form1()

        private void label2_Click(object sender, EventArgs e)


    private void button2_Click(object sender, EventArgs e)
            SmtpClient client = new SmtpClient("");
            client.Port = 587;
            client.EnableSsl = true;
            client.Timeout = 100000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(
              "", "yourgmailpassword");
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("");
            msg.Subject = textBox_Subject.Text;
            msg.Body = textBox_Message.Text;
            Attachment data = new Attachment(textBox_Attachment.Text);
            MessageBox.Show("Successfully Sent Message.");
        catch (Exception ex)

    private void button_Upload_Click(object sender, EventArgs e)
        OpenFileDialog dlg = new OpenFileDialog();
        if (dlg.ShowDialog() == DialogResult.OK)
            textBox_Attachment.Text = dlg.FileName.ToString();

If you have any questions, don’t hesitate to comment below. I will answer your questions and will try to give you the best solutions.

Now my next topic will be how we create a Web Browser using C# Windows Application Form.

You can also email me at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ehsan Ilahi
Software Developer (Junior)
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionI got error: failure sending mail Pin
Member 119423887-Oct-15 2:07
memberMember 119423887-Oct-15 2:07 
QuestionI get this following exception, please help me correcting it.. Pin
Badhusha Arabusha30-Aug-15 23:38
memberBadhusha Arabusha30-Aug-15 23:38 
Questioni got an error Pin
Member 111360055-Jan-15 13:28
memberMember 111360055-Jan-15 13:28 
AnswerRe: i got an error Pin
Member 1027016319-Jul-15 13:24
memberMember 1027016319-Jul-15 13:24 
Questionsend mail to multiple recepient Pin
Member 1062048628-Feb-14 20:11
memberMember 1062048628-Feb-14 20:11 
AnswerRe: send mail to multiple recepient Pin
Member 1027016319-Jul-15 13:18
memberMember 1027016319-Jul-15 13:18 
QuestionI got an error Pin
Stephin Francis4-Feb-14 1:12
memberStephin Francis4-Feb-14 1:12 
AnswerSolved Error 5.5.1 Pin
ananthsumo6-Aug-14 22:14
memberananthsumo6-Aug-14 22:14 
GeneralMy vote of 1 Pin
Ahmed Alaa El-Din11-Nov-13 7:31
memberAhmed Alaa El-Din11-Nov-13 7:31 
GeneralRe: My vote of 1 Pin
Ehsan Ilahi11-Nov-13 19:38
memberEhsan Ilahi11-Nov-13 19:38 
Suggestion[My vote of 1] This is not an Article. Pin
Debopam Pal10-Nov-13 18:46
memberDebopam Pal10-Nov-13 18:46 
GeneralRe: [My vote of 1] This is not an Article. Pin
Ehsan Ilahi11-Nov-13 19:35
memberEhsan Ilahi11-Nov-13 19:35 
GeneralMy vote of 1 Pin
Tammam Koujan9-Nov-13 23:52
professionalTammam Koujan9-Nov-13 23:52 
GeneralRe: My vote of 1 Pin
Ehsan Ilahi10-Nov-13 4:10
memberEhsan Ilahi10-Nov-13 4:10 
GeneralRe: My vote of 1 Pin
Tammam Koujan11-Nov-13 1:06
professionalTammam Koujan11-Nov-13 1:06 
Questionthe image is not available Pin
Tarek Elqusi9-Nov-13 11:46
memberTarek Elqusi9-Nov-13 11:46 
AnswerRe: the image is not available Pin
Ehsan Ilahi9-Nov-13 23:22
memberEhsan Ilahi9-Nov-13 23:22 
AnswerRe: the image is not available Pin
Ehsan Ilahi9-Nov-13 23:30
memberEhsan Ilahi9-Nov-13 23:30 
QuestionSome comments Pin
Ravi Bhavnani9-Nov-13 10:41
professionalRavi Bhavnani9-Nov-13 10:41 
AnswerRe: Some comments Pin
Ehsan Ilahi9-Nov-13 23:29
memberEhsan Ilahi9-Nov-13 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 10 Nov 2013
Article Copyright 2013 by Ehsan Ilahi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid