Click here to Skip to main content
15,936,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai, i am a freelancer trying to make a c# code for sending a email. I have coded as shown below.
But once i run my code, it shows that email sending has been failed because of not implementing 502 command.It would be kindful of you if you could correct my code below.Please help me.god bless you
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EASendMail; 

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            SmtpMail oMail = new SmtpMail("TryIt");
            SmtpClient oSmtp = new SmtpClient();

            // Set sender email address, please change it to yours
            oMail.From = "";

            // Set recipient email address, please change it to yours
            oMail.To = "";

            // Set email subject
            oMail.Subject = "test email from c# project";

            // Set email body
            oMail.TextBody = "this is a test email sent from c# project, do not reply";

            // Your SMTP server address
            SmtpServer oServer = new SmtpServer("");

            // User and password for ESMTP authentication, if your server doesn't require
            // User authentication, please remove the following codes.            
            oServer.User = "faizel.shk";
            oServer.Password = "***********";

            // If your smtp server requires SSL connection, please add this line
             oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

                Console.WriteLine("start to send email ...");
                oSmtp.SendMail(oServer, oMail);
                Console.WriteLine("email was sent successfully!");
            catch (Exception ep)
                Console.WriteLine("failed to send email with the following error:");
Updated 14-Mar-13 23:49pm
Karthik Harve 15-Mar-13 5:50am    
[Edit] pre tags added.

              string myEmailAddress = "A*********";
              string mypwd = "***************";
              string toEmailAddress = "";
              string subject = "Try to send mail";
              string mailbody = "this is try mail body";

           var client = new System.Net.Mail.SmtpClient("", 587)
                  Credentials = new System.Net.NetworkCredential(myEmailAddress, mypwd),
                  EnableSsl = true
           client.Send(myEmailAddress, toEmailAddress, subject, mailbody);


       catch (Exception e1)


Try it ...
Share this answer
Or SmtpServer oServer = new SmtpServer("");

Change to this line

SmtpServer oServer = new SmtpServer("", 587);
Share this answer
Nelek 15-Mar-13 13:03pm    
If you need to add or change content to your question or a previous solution, please use the "improve question / solution" instead of writing a lot of messages. It will keep readability and help other users with similar problems to find it faster.

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900