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

Tagged as

Send Email from Yahoo!, GMail, Hotmail (C#)

, 27 Sep 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Sending email easily from Yahoo!, GMail, Hotmail in C#.

Server Parameters

Server Name SMTP Address Port SSL
Yahoo! 587 Yes
GMail 587 Yes
Hotmail 587 Yes

Sample Code

using System.Net;
using System.Net.Mail;

string smtpAddress = "";
int portNumber = 587;
bool enableSSL = true;

string emailFrom = "";
string password = "abcdefg";
string emailTo = "";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";

using (MailMessage mail = new MailMessage())
    mail.From = new MailAddress(emailFrom);
    mail.Subject = subject;
    mail.Body = body;
    mail.IsBodyHtml = true;
    // Can set to false, if you are sending pure text.

    mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
    mail.Attachments.Add(new Attachment("C:\\"));

    using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
        smtp.Credentials = new NetworkCredential(emailFrom, password);
        smtp.EnableSsl = enableSSL;


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


About the Author

Software Developer
Malaysia Malaysia
Writing programs is an art.

Comments and Discussions

GeneralMy vote of 1 PinmemberTalwinder.Gur22-Feb-15 20:12 
GeneralRe: My vote of 1 Pinmvpadriancs24-Feb-15 13:05 
QuestionGetting Error PinprofessionalMember 1046902731-Aug-14 2:10 
AnswerRe: Getting Error Pinprofessionaladriancs31-Aug-14 4:33 
QuestionProxy Usage.. PinmemberMusab Hussain21-Aug-14 4:56 
QuestionCould not send the e-mail - error: Failure sending mail. PinmemberMember 109250676-Aug-14 5:46 
QuestionVery nice code PinmemberMember 1033383527-Mar-14 11:02 
QuestionWaOoo! PinmemberBlue_sky00730-Sep-13 7:32 
GeneralMy vote of 5 PinmemberPCoffey27-Sep-13 7:47 
GeneralMy vote of 5 PinmemberWooters27-Sep-13 7:29 
GeneralMy vote of 5 PinmemberS.M. Moosavi27-Sep-13 5:46 
GeneralMy vote of 5 PinmemberMember 892926517-Aug-13 12:23 
QuestionNice POST Pinmemberboss prabu4-Jun-13 8:24 
AnswerRe: Nice POST [modified] PinmemberBlue_sky00730-Sep-13 6:52 
GeneralNice work PinmemberMustafaHamed29-Apr-13 6:34 
QuestionException Pinmembermughal_158324-Feb-13 23:52 
AnswerRe: Exception Pinmvpadriancs26-Sep-13 19:24 
GeneralMy vote of 5 PinmemberEdo Tzumer5-Jan-13 22:36 

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
Web03 | 2.8.150301.1 | Last Updated 27 Sep 2013
Article Copyright 2013 by adriancs
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid