using System; using System.Collections.Generic; using System.Text; using System.Net.Mail; using System.Net.Mime; namespace Emailclient { class Program { static void Main(string[] args) { string sender, receipents; MailMessage msgobj = new MailMessage(); SmtpClient client = new SmtpClient(); client.Host = "smtp.gmail.com"; // client.Host="www.yahoo.com"; //client.Port = 587; client.EnableSsl = true; Console.WriteLine(".................Email Client Version 1.0.0.0........."); Console.Write(".................Printing the Service point protocol version........"); Console.Write(client.ServicePoint.ProtocolVersion.ToString()); if (client.Credentials == null) { //Console.WriteLine("..............Credentials are set to null............"); // username and password Is set as ceredntial for connecting to smtp accesss to gmail account client.Credentials = new System.Net.NetworkCredential("**your email id", "password"); } Console.WriteLine("..............Enter your email address here and press Enter.........."); try { // sender's emaill address ....... // sender = Console.ReadLine(); msgobj.From = new MailAddress("niraj.1991@gmail.com"); Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine("Sending mail on the behalf of niraj.1991@gmail.com"); } catch (FormatException fe) { Console.WriteLine("Following Error Ocured.......\n" + fe.Message); Console.Clear(); Console.WriteLine("..............Enter your email address here and press Enter.........."); sender= Console.ReadLine(); msgobj.From = new MailAddress(sender); } Console.WriteLine("Enter your friend's email address here and press Enter.........."); try { // emaill addresses of recepients goes here........ Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.DarkCyan; receipents = Console.ReadLine(); msgobj.To.Add ( receipents); } catch (FormatException fe2) { Console.WriteLine("Following Error Ocured.......\n" + fe2.Message); Console.Clear(); Console.WriteLine("Enter your friend's email address here and press Enter.........."); Console.ForegroundColor=ConsoleColor.Red; Console.WriteLine("Following Error Ocured.......\n" + fe2.Message); Console.Read(); // Console.WriteLine("Press esc key to exit"); } Console.WriteLine(".........Enter subject of the message......."); msgobj.Subject = Console.ReadLine().ToString(); // msgobj.Attachments =new AttachmentCollection("C:\\Documents and Settings\\NIRAJ KUMAR CHAUHAN\\Desktop\\exception"); // msgobj.BodyEncoding=System.Text.Encoding.ASCII; msgobj.IsBodyHtml=true; //TransferEncoding.Base64; msgobj.Priority=MailPriority.High; Console.WriteLine("........Enter your message body here..........."); msgobj.Body = Console.Read().ToString(); Console.WriteLine("..........Sending message to " + msgobj.To.ToString()+".........."); try { client.Send(msgobj); } catch (SmtpException e) { Console.WriteLine(" ......Serious Error occured " + e.Message); Console.Read(); } /* Console.WriteLine("Message send successfulluy....."); else Console.WriteLine("Mesaage sending failed......");*/ Console.Read(); } } }
msgobj.IsBodyHtml = true;
msgobj.IsBodyHtml=true;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)