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
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! smtp.mail.yahoo.com 587 Yes
GMail smtp.gmail.com 587 Yes
Hotmail smtp.live.com 587 Yes

Sample Code

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

string smtpAddress = "smtp.mail.yahoo.com";
int portNumber = 587;
bool enableSSL = true;

string emailFrom = "email@yahoo.com";
string password = "abcdefg";
string emailTo = "someone@domain.com";
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.To.Add(emailTo);
    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:\\SomeZip.zip"));

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

License

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

Share

About the Author

adriancs
Software Developer
Malaysia Malaysia
Writing programs is an art.

Comments and Discussions

 
QuestionGetting Error PinprofessionalMember 1046902731-Aug-14 1:10 
AnswerRe: Getting Error Pinpremiumadriancs31-Aug-14 3:33 
QuestionProxy Usage.. PinmemberMusab Hussain21-Aug-14 3:56 
QuestionCould not send the e-mail - error: Failure sending mail. PinmemberMember 109250676-Aug-14 4:46 
QuestionVery nice code PinmemberMember 1033383527-Mar-14 10:02 
QuestionWaOoo! PinmemberBlue_sky00730-Sep-13 6:32 
GeneralMy vote of 5 PinmemberPCoffey27-Sep-13 6:47 
GeneralMy vote of 5 PinmemberWooters27-Sep-13 6:29 
GeneralMy vote of 5 PinmemberS.M. Moosavi27-Sep-13 4:46 
GeneralMy vote of 5 PinmemberMember 892926517-Aug-13 11:23 
QuestionNice POST Pinmemberboss prabu4-Jun-13 7:24 
AnswerRe: Nice POST [modified] PinmemberBlue_sky00730-Sep-13 5:52 
GeneralNice work PinmemberMustafaHamed29-Apr-13 5:34 
QuestionException Pinmembermughal_158324-Feb-13 22:52 
AnswerRe: Exception Pinmvpadriancs26-Sep-13 18:24 
GeneralMy vote of 5 PinmemberEdo Tzumer5-Jan-13 21: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 | Mobile
Web02 | 2.8.140827.1 | Last Updated 27 Sep 2013
Article Copyright 2013 by adriancs
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid