Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

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

, 19 Dec 2011
Rate this:
Please Sign up or sign in to vote.
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...

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
No Biography provided

Comments and Discussions

 
GeneralThat's where I did a lot of my practice was that MSDN. A per... PinmemberRobert Widmark26-Dec-11 21:31 

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.140721.1 | Last Updated 19 Dec 2011
Article Copyright 2011 by Robert S Sharp
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid