Click here to Skip to main content
Click here to Skip to main content
Go to top

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

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

Introduction

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 “smtp.gmail.com” 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()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

    private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.Port = 587;
            client.EnableSsl = true;
            client.Timeout = 100000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(
              "yourid@gmail.com", "yourgmailpassword");
            MailMessage msg = new MailMessage();
            msg.To.Add(textBox_To.Text);
            msg.From = new MailAddress("yourid@gmail.com");
            msg.Subject = textBox_Subject.Text;
            msg.Body = textBox_Message.Text;
            Attachment data = new Attachment(textBox_Attachment.Text);
            msg.Attachments.Add(data);
            client.Send(msg);
            MessageBox.Show("Successfully Sent Message.");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    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 ehsanilahi77@gmail.com.

License

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

Share

About the Author

Ehsan Ilahi
Software Developer (Junior)
Pakistan Pakistan
No Biography provided
Follow on   Twitter   Google+

Comments and Discussions

 
Questionsend mail to multiple recepient PinmemberMember 1062048628-Feb-14 19:11 
QuestionI got an error PinmemberStephin Francis4-Feb-14 0:12 
AnswerSolved Error 5.5.1 Pinmemberananthsumo6-Aug-14 21:14 
GeneralMy vote of 1 PinmemberAhmed Alaa El-Din11-Nov-13 6:31 
GeneralRe: My vote of 1 PinmemberEhsan Ilahi11-Nov-13 18:38 
Suggestion[My vote of 1] This is not an Article. PinmemberDebopam Pal10-Nov-13 17:46 
GeneralRe: [My vote of 1] This is not an Article. PinmemberEhsan Ilahi11-Nov-13 18:35 
GeneralMy vote of 1 PinprofessionalTammam Koujan9-Nov-13 22:52 
GeneralRe: My vote of 1 PinmemberEhsan Ilahi10-Nov-13 3:10 
GeneralRe: My vote of 1 PinprofessionalTammam Koujan11-Nov-13 0:06 
Even if it is for beginners there is nothing new!, a lot of articles about the same subject
available in CodeProject , as example:
Using Gmail Account to Send Emails With Attachment[^]
Email Sender[^]
 
You should search before posting
Questionthe image is not available PinmemberTarek Elqusi9-Nov-13 10:46 
AnswerRe: the image is not available PinmemberEhsan Ilahi9-Nov-13 22:22 
AnswerRe: the image is not available PinmemberEhsan Ilahi9-Nov-13 22:30 
QuestionSome comments PinprofessionalRavi Bhavnani9-Nov-13 9:41 
AnswerRe: Some comments PinmemberEhsan Ilahi9-Nov-13 22:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.8.140922.1 | Last Updated 10 Nov 2013
Article Copyright 2013 by Ehsan Ilahi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid