Upload
manoj-kumar-g
View
407
Download
5
Embed Size (px)
DESCRIPTION
Send Email From Yahoo, Gmail, Hotmail (C#) - CodeProject
Citation preview
highlights off
9,890,640 members (46,312 online) 2K Sign out
Not quite what you are looking for? You may want to try:Send 1000s of Emails Without TimeoutSending Email Using Embedded Images
×
manuu
home quick answers discussions features community help send email in c#
Articles » General Programming » Internet / Network » Email & SMTP
Tip
Browse Code
Stats
Revisions (4)
Alternatives
Comments &Discussions (3)
Add your ownalternative version
About Article
A Class for Sending EmailEasily from Yahoo, Gmail,Hotmail or your own email.
Type Tip/Trick
Licence CPOL
First Posted 3 Jan 2013
Views 8,453
Downloads 860
Bookmarked 21 times
C# Beginner
Top News
The Next Version ofAndroid - Some of What'sComing
Get the Insider News free eachmorning.
Related Videos
HTML5 - 0303 Links To Files
Next
Send Email from Yahoo, Gmail, Hotmail (C#)By adriancs, 3 Jan 2013
Download EmailSender.zip
IntroductionA Class for Sending Email Easily from Yahoo, Gmail, Hotmail or your own email.
Using the codeSending Email from Yahoo Mail.
Collapse | Copy Code
EmailSender es = new EmailSender();es.From = "[email protected]";es.To = "[email protected]";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");
or
Collapse | Copy Code
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
using System.Net.Mail;using System.Net;
Sending email from Yahoo Mail:
4.75 (4 votes)
articles
Send Email from Yahoo, Gmail, Hotmail (C#) - CodeProject http://www.codeproject.com/Tips/520998/Send-Email-from-Yahoo-Gm...
1 of 3 25/05/2013 01:24
And Email
Windows 8: Sending WNSPush Notifications Part 2
Related ArticlesA POP3 Client in C# .NET
Sending Email using MAPI - ACOM DLL
Using Gmail Account to SendEmails With Attachment
BooProd.BMail - Sendingdynamically generated emails
C# Code snippet to send anEmail with attachment fromOutlook, Yahoo, HotMail, AOLand Gmail
Mail Monitor++
MySendToMail: A Replacementfor Windows SendTo/Email
Send Calendar Appointment AsEmail Attachment
System.Web.Mail and thepickup directory
Sending Emails using .NET PartII
Send 1000s of Emails WithoutTimeout
How to send an SMS messagefrom an application
A class for sending emails withattachments in C#.
What not to do: Anti-Patternsand the Solutions
IP Announce by Email
A versatile HTML form mailscript for classic ASP
Sending Email Using EmbeddedImages
Sending Email through ASP.NET
VB.NET 2005 SMTP EmailMessage
Windows Email Clientapplication using .NET (C#)
Article Top 0 Tweet 13 Rate this: Poor Excellent Vote
Add a Comment or Question Search this forum Go
Collapse | Copy Code
using (var client = new SmtpClient("smtp.mail.yahoo.com", 587)){ client.Credentials = new NetworkCredential("[email protected]", "mypwd"); var mail = new MailMessage(); mail.From = new MailAddress("[email protected]"); mail.To.Add("[email protected]"); mail.Subject = "Test mail"; mail.Body = "test body"; client.Send(mail);}
Note: In earlier version of .NET Framework, SmtpClient has not implement IDisposable. Therefore, you can't useUsing to declare it.
Sending email from Gmail:
Collapse | Copy Code
using (var client = new SmtpClient("smtp.gmail.com", 587)){ client.Credentials = new NetworkCredential("[email protected]", "mypwd"); var mail = new MailMessage(); ... ... client.EnableSsl = true; client.Send(mail);}
Sending email from Hotmail / Windows Live Mail
Collapse | Copy Code
using (var client = new SmtpClient("smtp.live.com", 587)){ client.Credentials = new NetworkCredential("[email protected]", "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.
LicenseThis article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
About the Author
adriancsSoftware Developer
Malaysia Member
Another guy from Sabah.
Comments and Discussions
Profile popups Spacing Relaxed Noise Medium Layout Open All Per page 25 Update
First Prev Next
MustafaHamed 29 Apr '13 - 7:34
with a little tweak it works fine for me thanks, nice work Mustafa Hamed
Reply · Email ·View Thread ·Permalink ·Bookmark
mughal_1583 25 Feb '13 - 0:52
Like 2
Nice work
Exception
Send Email from Yahoo, Gmail, Hotmail (C#) - CodeProject http://www.codeproject.com/Tips/520998/Send-Email-from-Yahoo-Gm...
2 of 3 25/05/2013 01:24
Permalink | Advertise | Privacy | MobileWeb03 | 2.6.130523.1 | Last Updated 3 Jan 2013
Article Copyright 2013 by adriancsEverything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid
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 unhandledMessage=Failure sending mail.Source=SystemStackTrace: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 158at EmailSender.Send() in C:\Users\Mughal\documents\visual studio 2010\Projects\TestingEmail\TestingEmail\EmailSender.cs:line 100at TestingEmail.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Mughal\documents\visual studio 2010\Projects\TestingEmail\TestingEmail\Form1.cs:line 34at 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)atSystem.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtrdwComponentID, 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 18at 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.IOExceptionMessage=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.Source=SystemStackTrace: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.SocketExceptionMessage=An existing connection was forcibly closed by the remote hostSource=SystemErrorCode=10054NativeErrorCode=10054StackTrace: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
Edo Tzumer 5 Jan '13 - 23:36
Nice work,keep it simple
Reply · Email ·View Thread ·Permalink ·Bookmark
Last Visit: 23 May '13 - 6:50 Last Update: 23 May '13 - 19:50 Refresh 1
General News Suggestion Question Bug Answer Joke Rant Admin
My vote of 5
Send Email from Yahoo, Gmail, Hotmail (C#) - CodeProject http://www.codeproject.com/Tips/520998/Send-Email-from-Yahoo-Gm...
3 of 3 25/05/2013 01:24