Click here to Skip to main content
11,409,138 members (49,733 online)
Click here to Skip to main content

Simple SMTP E-Mail Sender in C#… Console application

, 27 Feb 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Simple SMTP E-Mail Sender in C#… Console application
I've been all over the Internet, as a beginner looking for examples for a simple e-mail sender program.
I was looking for a simple structure to follow. Something I could look at & say to myself, "okay, I think I can understand that".

Some examples I found were either outdated for today's .NET Network or there were over 100 lines of code & the article said, "Simple"…

My way of giving back is to post this article. I've read some articles here, "The Code Project & MSDN". Both places were very helpful regarding information and help.

For the old pros, I've been told I need to add some sort of garbage collection, which I will gladly do when I learn how.
For now, it's working… And it is, "Simple".
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;
class Program
    static void Main(string[] args)
        Console.WriteLine("Mail To");
        MailAddress to = new MailAddress(Console.ReadLine());
        Console.WriteLine("Mail From");
        MailAddress from = new MailAddress(Console.ReadLine());
        MailMessage mail = new MailMessage(from, to);
        mail.Subject = Console.ReadLine();
        Console.WriteLine("Your Message");
        mail.Body = Console.ReadLine();
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "";
        smtp.Port = 587;
        smtp.Credentials = new NetworkCredential(
            "", "password");
        smtp.EnableSsl = true;
        Console.WriteLine("Sending email...");

As far as I know, you can use this with any SMTP server… More specifically the free ones, Gmail; Yahoo mail; AOL…
I have not tested it on a private server…


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


About the Author

Website Administrator
United States United States
No Biography provided
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

Questiondispose() PinmemberGideon Cole13-Mar-15 1:59 
QuestionProblem PinmemberAsad Marfani18-Oct-14 11:04 
Questionvery nice Pinmemberyechengmiao11-Mar-14 23:11 
GeneralVery Cool 7 Simple 7 Helpful PinmemberNew DotNet Developer31-Jan-14 6:47 
GeneralMy vote of 5 PinmemberАslam Iqbal30-Mar-13 7:35 
QuestionFailure sending message error.. Pinmemberburdz10-Oct-12 0:30 
AnswerRe: Failure sending message error.. PinmemberWidmarkRob10-Oct-12 1:13 
AnswerRe: Failure sending message error.. PinmemberАslam Iqbal30-Mar-13 7:40 
AnswerRe: Failure sending message error.. PinmemberWidmarkRob2-Apr-15 16:42 
GeneralJust a small hint ;) PinmemberNicholas Marty5-Mar-12 6:14 
GeneralRe: Just a small hint ;) PinmemberWidmarkRob10-Apr-12 23:58 
GeneralRe: thanks :) PinmemberMokhtar Ashour29-Dec-11 5:22 
GeneralReason for my vote of 5 Awesome Example for beginners. PinmemberBalakrishnan Dhinakaran29-Feb-12 21:26 
GeneralReason for my vote of 4 Nice example - and "simple" Pinmemberbrother.gabriel29-Feb-12 13:10 
GeneralReason for my vote of 5 simple and powerful PinmemberMokhtar Ashour29-Dec-11 5:23 
Generalsimple and easy, but the question is "is it secured"? I don'... PinmemberMokhtar Ashour27-Dec-11 10:38 
GeneralRe: SSL - Secured Socket Layer is enabled. I'm assuming it's enc... PinmemberRobert Widmark29-Dec-11 1:39 
GeneralReason for my vote of 5 good one! Pinmembervelt_99126-Dec-11 21:48 
GeneralRe: Thank You PinmemberRobert Widmark29-Dec-11 1:39 
GeneralCheck out PinmemberAxel Rietschin19-Dec-11 10:59 

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 | Terms of Use | Mobile
Web02 | 2.8.150414.5 | Last Updated 28 Feb 2012
Article Copyright 2011 by N8tiv
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid