Sie sind auf Seite 1von 3

Send Email from Yahoo, Gmail, Hotmail (C#) - CodeProject

http://www.codeproject.com/Tips/520998/Send-Email-from-Yahoo-Gm...

Not quite what you are looking for? You may want to try: Send 1000s of Emails Without Timeout Sending Email Using Embedded Images
9,890,640 members (46,312 online) manuu 2K

highlights off
Sign out

home

articles

quick answers

discussions

features

community

help

send email in c#

Articles General Programming Internet / Network Email & SMTP

Next

Tip Browse Code Stats Revisions (4) Alternatives

Send Email from Yahoo, Gmail, Hotmail (C#)


By adriancs, 3 Jan 2013
4.75 (4 votes)

About Article
A Class for Sending Email Easily from Yahoo, Gmail, Hotmail or your own email. Type Licence Tip/Trick CPOL 3 Jan 2013 8,453 860 21 times

Download EmailSender.zip
Comments & Discussions (3)

Introduction
A Class for Sending Email Easily from Yahoo, Gmail, Hotmail or your own email.

First Posted Views Downloads Bookmarked

Add your own alternative version

Using the code


Sending Email from Yahoo Mail.
Collapse | Copy Code

C# Beginner

EmailSender es = new EmailSender(); es.From = "myemail@yahoo.com"; es.To = "anyaddress@anydomain.com"; es.Password = "mypwd"; es.Subject = "Test Mail"; es.Body = "hello"; es.IsHtmlBody = false; es.EmailProvider = EmailSender.EmailProviderType.Yahoo; es.Send();

Sending Email from Gmail. Change the EmailProvider to Gmail


Collapse | Copy Code

es.EmailProvider = EmailSender.EmailProviderType.Gmail;

Sending Email from Hotmail/Windows Live . Change the EmailProvider to Hotmail


Collapse | Copy Code

es.EmailProvider = EmailSender.EmailProviderType.Hotmail;

Sending Email from your own domain. Change the EmailProvider to Other
Collapse | Copy Code

es.EmailProvider = EmailSender.EmailProviderType.Other; es.Host = "smtp.mydomain.com"; es.Port = 25; es.EnableSSL = false;

To add single file as attachment.


Collapse | Copy Code

es.AttachFile = "C:\\MyFile.zip";

To add multiple files as attachments.


Collapse | Copy Code

es.AttachmentFileList.Add("C:\\MyFile1.zip"); es.AttachmentFileList.Add("C:\\MyFile2.zip");

Top News
Collapse | Copy Code

or The Next Version of Android - Some of What's Coming


Get the Insider News free each morning.

es.AttachmentFileArray = new string[] { "C:\\MyFile1.zip", "C:\\MyFile2.zip" };

Class of EmailSender: Download available at top.

Sending Email Without Using Class of EmailSender


Collapse | Copy Code

Related Videos

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

Sending email from Yahoo Mail:

HTML 5 - 0303 Links To Files

1 of 3

25/05/2013 01:24

Send Email from Yahoo, Gmail, Hotmail (C#) - CodeProject

http://www.codeproject.com/Tips/520998/Send-Email-from-Yahoo-Gm...

Collapse | Copy Code

And Email

using (var client = new SmtpClient("smtp.mail.yahoo.com", 587)) { client.Credentials = new NetworkCredential("myemail@yahoo.com", "mypwd"); var mail = new MailMessage(); mail.From = new MailAddress("myemail@yahoo.com"); mail.To.Add("anyaddress@anydomain.com"); mail.Subject = "Test mail"; mail.Body = "test body"; client.Send(mail); }

Windows 8: Sending WNS Push Notifications Part 2

Note: In earlier version of .NET Framework, SmtpClient has not implement IDisposable. Therefore, you can't use Using to declare it. Sending email from Gmail:
Collapse | Copy Code

Related Articles
A POP3 Client in C# .NET Sending Email using MAPI - A COM DLL Using Gmail Account to Send Emails With Attachment BooProd.BMail - Sending dynamically generated emails C# Code snippet to send an Email with attachment from Outlook, Yahoo, HotMail, AOL and Gmail Mail Monitor++

using (var client = new SmtpClient("smtp.gmail.com", 587)) { client.Credentials = new NetworkCredential("myemail@gmail.com", "mypwd"); var mail = new MailMessage(); ... ... client.EnableSsl = true; client.Send(mail); }

Sending email from Hotmail / Windows Live Mail


Collapse | Copy Code

MySendToMail: A Replacement for Windows SendTo/Email Send Calendar Appointment As Email Attachment System.Web.Mail and the pickup directory Sending Emails using .NET Part II Send 1000s of Emails Without Timeout How to send an SMS message from an application A class for sending emails with attachments in C#.

using (var client = new SmtpClient("smtp.live.com", 587)) { client.Credentials = new NetworkCredential("myemail@live.com", "mypwd"); var mail = new MailMessage(); ... ... client.EnableSsl = true; client.Send(mail); }

Alternatively, you may refer OriginalGriff's examples: Sending an Email in C# with or without attachments: generic routine.

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

What not to do: Anti-Patterns and the Solutions IP Announce by Email A versatile HTML form mail script for classic ASP

About the Author


adriancs
Software Developer Malaysia Member Another guy from Sabah.

Sending Email Using Embedded Images Sending Email through ASP. NET VB.NET 2005 SMTP Email Message Windows Email Client application using .NET (C#)

Article Top

Like

Tweet

13

Rate this:

Poor

Excellent

Vote

Comments and Discussions


Add a Comment or Question
Profile popups Spacing Relaxed Search this forum Go

Noise Medium

Layout Open All

Per page 25

Update

First Prev Next

Nice work
with a little tweak it works fine for me thanks, nice work Mustafa Hamed
Reply Email View Thread Permalink Bookmark

MustafaHamed

29 Apr '13 - 7:34

Exception

mughal_1583

25 Feb '13 - 0:52

2 of 3

25/05/2013 01:24

Send Email from Yahoo, Gmail, Hotmail (C#) - CodeProject

http://www.codeproject.com/Tips/520998/Send-Email-from-Yahoo-Gm...

I am getting exception while running this code, i m using window 7 with vs 2010. Kindly guide me in this regard System.Net.Mail.SmtpException was unhandled Message=Failure sending mail. Source=System StackTrace: at System.Net.Mail.SmtpClient.Send(MailMessage message) at EmailSender.SendMail(MailMessage mail) in C:\Users\Mughal\documents\visual studio 2010\Projects\TestingEmail\TestingEmail\EmailSender.cs:line 158 at EmailSender.Send() in C:\Users\Mughal\documents\visual studio 2010\Projects\TestingEmail\TestingEmail\EmailSender.cs:line 100 at TestingEmail.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Mughal\documents\visual studio 2010\Projects\TestingEmail\TestingEmail \Form1.cs:line 34 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at TestingEmail.Program.Main() in C:\Users\Mughal\Documents\Visual Studio 2010\Projects\TestingEmail\TestingEmail\Program.cs:line 18 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.IO.IOException Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Source=System StackTrace: at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) at System.Net.Mail.StartTlsCommand.Send(SmtpConnection conn) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) InnerException: System.Net.Sockets.SocketException Message=An existing connection was forcibly closed by the remote host Source=System ErrorCode=10054 NativeErrorCode=10054 StackTrace: at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) InnerException:
Reply Email View Thread Permalink Bookmark

My vote of 5
Nice work, keep it simple
Reply Email View Thread Permalink Bookmark

Edo Tzumer

5 Jan '13 - 23:36

Last Visit: 23 May '13 - 6:50

Last Update: 23 May '13 - 19:50

Refresh

General

News

Suggestion

Question

Bug

Answer

Joke

Rant

Admin
Article Copyright 2013 by adriancs Everything else Copyright CodeProject, 1999-2013 Terms of Use

Permalink | Advertise | Privacy | Mobile Web03 | 2.6.130523.1 | Last Updated 3 Jan 2013

Layout: fixed | fluid

3 of 3

25/05/2013 01:24

Das könnte Ihnen auch gefallen