Click here to Skip to main content
Click here to Skip to main content

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

By , 19 Dec 2011
 

I'm not sure that GC would matter very much in such a simple app.

But, it's either a call to Dispose on your SmtpClient after you're done using it:

smtp.Dispose();

or use a using:

using (SmtpClient smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    Credentials = new NetworkCredential("user@gmail.com", "password"),
    EnableSsl = true
})
{
    smtp.Send(mail);
}

The using will take care of calling Dispose for you.

Also, don't forget that there's a convenience method on the SmtpClient, if you don't need anything fancy on the message like HTML formatting or attachments.

smtp.Send(from, to, subject, body);

License

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

About the Author

Robert S Sharp
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralI just wanted to say "Thanks"...groupAnnyclerk28 Dec '11 - 1:01 
I just wanted to say "Thanks"...
GeneralRe: My PleasurememberRobert Widmark29 Dec '11 - 0:40 
My Pleasure
GeneralThat's where I did a lot of my practice was that MSDN. A per...memberRobert Widmark26 Dec '11 - 21:31 
That's where I did a lot of my practice was that MSDN.
A person named, "Reed"… Gave me a lot of help from the MSDN forums.
GeneralLooks like example from MSDN :)memberNeoPunk20 Dec '11 - 8:55 
Looks like example from MSDN Smile | :)
GeneralI'm really new to programming in general. I guess I should h...memberRobert Widmark19 Dec '11 - 14:30 
I'm really new to programming in general.
I guess I should have mentioned, "I needed something a bit more difficult then the traditional, 'Hello World Application' to practice & to look at"…
Something I could look at line by line & say to myself, "okay, I think I can understand that"…
I'm not trying to reinvent the wheel. I just needed a less confusing,, cleaner wheel to learn from.
I hope that made sense.
I will most likely build on this & I'm not sure what I'll start with… Maybe the ability to add an attachment, then later on incorporate HTML & an address book.
I'm a slow baby steps learner. Smile | :)
GeneralNice and clean. I like it. +5memberMarcus Kramer19 Dec '11 - 10:29 
Nice and clean. I like it. +5
GeneralRe: Thank YoumemberRobert Widmark29 Dec '11 - 0:40 
Thank You

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 19 Dec 2011
Article Copyright 2011 by Robert S Sharp
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid