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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
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 
GeneralThat's where I did a lot of my practice was that MSDN. A per...memberRobert Widmark26 Dec '11 - 21:31 
GeneralLooks like example from MSDN :)memberNeoPunk20 Dec '11 - 8:55 
GeneralI'm really new to programming in general. I guess I should h...memberRobert Widmark19 Dec '11 - 14:30 
GeneralNice and clean. I like it. +5memberMarcus Kramer19 Dec '11 - 10:29 
GeneralRe: Thank YoumemberRobert Widmark29 Dec '11 - 0:40 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 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