Click here to Skip to main content
11,491,598 members (71,514 online)
Click here to Skip to main content

Tagged as

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

, 27 Sep 2013 CPOL 91.9K 1.8K 74
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

 
QuestionThanks Pin
trivedijignesh23-May-15 20:55
membertrivedijignesh23-May-15 20:55 
Questionthanks , you save my time Pin
mehrdadhj27-Mar-15 14:51
membermehrdadhj27-Mar-15 14:51 
GeneralMy vote of 1 Pin
Talwinder.Gur22-Feb-15 20:12
memberTalwinder.Gur22-Feb-15 20:12 
GeneralRe: My vote of 1 Pin
adriancs24-Feb-15 13:05
mvpadriancs24-Feb-15 13:05 
QuestionGetting Error Pin
Member 1046902731-Aug-14 2:10
professionalMember 1046902731-Aug-14 2:10 
AnswerRe: Getting Error Pin
adriancs31-Aug-14 4:33
professionaladriancs31-Aug-14 4:33 
GeneralRe: Getting Error [modified] Pin
Iparke15-Mar-15 23:34
memberIparke15-Mar-15 23:34 
QuestionProxy Usage.. Pin
Musab Hussain21-Aug-14 4:56
memberMusab Hussain21-Aug-14 4:56 
QuestionCould not send the e-mail - error: Failure sending mail. Pin
Member 109250676-Aug-14 5:46
memberMember 109250676-Aug-14 5:46 
QuestionVery nice code Pin
Member 1033383527-Mar-14 11:02
memberMember 1033383527-Mar-14 11:02 
QuestionWaOoo! Pin
Blue_sky00730-Sep-13 7:32
memberBlue_sky00730-Sep-13 7:32 
GeneralMy vote of 5 Pin
PCoffey27-Sep-13 7:47
memberPCoffey27-Sep-13 7:47 
GeneralMy vote of 5 Pin
Wooters27-Sep-13 7:29
memberWooters27-Sep-13 7:29 
GeneralMy vote of 5 Pin
S.M. Moosavi27-Sep-13 5:46
memberS.M. Moosavi27-Sep-13 5:46 
GeneralMy vote of 5 Pin
Member 892926517-Aug-13 12:23
memberMember 892926517-Aug-13 12:23 
QuestionNice POST Pin
boss prabu4-Jun-13 8:24
memberboss prabu4-Jun-13 8:24 
AnswerRe: Nice POST [modified] Pin
Blue_sky00730-Sep-13 6:52
memberBlue_sky00730-Sep-13 6:52 
GeneralNice work Pin
MustafaHamed29-Apr-13 6:34
memberMustafaHamed29-Apr-13 6:34 
QuestionException Pin
mughal_158324-Feb-13 23:52
membermughal_158324-Feb-13 23:52 
AnswerRe: Exception Pin
adriancs26-Sep-13 19:24
mvpadriancs26-Sep-13 19:24 
GeneralMy vote of 5 Pin
Edo Tzumer5-Jan-13 22:36
memberEdo 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
Web04 | 2.8.150520.1 | Last Updated 27 Sep 2013
Article Copyright 2013 by adriancs
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid