Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9297389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:04:02+00:00 2026-06-18T22:04:02+00:00

I am trying to send email to some of my colleagues using a program.

  • 0

I am trying to send email to some of my colleagues using a program. This program is working fine at my own desktop but is giving an error

Bad sequence of commands. The server response was: You must authenticate first (#5.5.1)

on one of our servers in remote location. Can someone point out the error I have tried to change the position of the line of authentication. And I am not able to deduce much from the error. The same username and password are being used at both locations.

public static Boolean sendemail(String strFrom, string strTo, string strCC, string strBCC, string strReplyTO, string strSubject, string strBody, string strAttachmentPath, bool IsBodyHTML)
    {
        //Array arrToArray;
        //char[] splitter = { ';' };
        //arrToArray = strTo.Split(splitter);
        MailMessage mm = new MailMessage();
        bool flag = isEmailsString(strFrom);
        if (flag)
        {
            mm.From = new MailAddress(strFrom);
        }
        flag = isEmailsString(strTo);
        if (flag)
        {
            mm.To.Add(strTo);
        }
        flag = isEmailsString(strCC);
        if (flag)
        {
            mm.CC.Add(strCC);
        }
        flag = isEmailsString(strBCC);
        if (flag)
        {
            mm.Bcc.Add(strBCC);
        }

        flag = Regex.IsMatch(strReplyTO.Trim(), @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
        if (strReplyTO != null)
        {
            if (flag)
            {
                mm.ReplyTo = new MailAddress(strReplyTO);
            }
        }

        if (strSubject != null)
        {
            mm.Subject = strSubject;
        }
        mm.IsBodyHtml = IsBodyHTML;
        if (!string.IsNullOrEmpty(strAttachmentPath))
        {
            Array attachmentArray;
            char[] attachSplitter = { ',' };
            attachmentArray = strAttachmentPath.Split(attachSplitter);
            foreach (string s in attachmentArray)
            {
                string st = s.Trim();
                if (!string.IsNullOrEmpty(st))
                {
                    Attachment attach = new Attachment(st);
                    // Add the file attachment to this e-mail message.
                    mm.Attachments.Add(attach);
                    //strBodyFinal.Append(Environment.NewLine+"Go to the following link for more information"+Environment.NewLine);
                    //strBodyFinal.Append(st);
                }
            }
        }
        if (strBody != null)
        {
            mm.Body = strBody;
        }
        //foreach (string s in arrToArray)
        // {
        //     mm.To.Add(new MailAddress(s));
        // }
        SmtpClient smtp = new SmtpClient();
        try
        {
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = "my user name";
            NetworkCred.Password = "my password";
            smtp.Credentials = NetworkCred;
            smtp.Host = "my company mail site";//host of your mail account
            //smtp.EnableSsl = true;

            smtp.UseDefaultCredentials = false;
            smtp.Port = 2525;//port no of your mail account 
            smtp.Timeout = 500000;
            smtp.Send(mm);
            return true;

        }
        catch (Exception ex)
        {
            mm.Dispose();
            smtp = null;
            Console.WriteLine(ex.Message, ex.StackTrace);
            return false;
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:04:05+00:00Added an answer on June 18, 2026 at 10:04 pm

    I searched a lot about the issue and finding different interpretations for the error message like: MAIL command issued after BDAT command so it says Bad sequence of commands. But actually the problem was sorted when I changed my code above to

    SmtpClient smtp = new SmtpClient();
    smtp.UseDefaultCredentials = false; // <<<you need THIS
    System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
    NetworkCred.UserName = "my user name";
    NetworkCred.Password = "my password";
    smtp.Credentials = NetworkCred;
    smtp.Host = "my company mail site";//host of your mail account
    smtp.Port = 2525;//port no of your mail account 
    smtp.Timeout = 500000;
    smtp.Send(mm);
    

    Notice that UseDefaultCredentials is set to false before the Credentials are assigned new credentials. This change of sequence of setting default to false magically worked for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason I am getting this error when trying to send an email
I am trying to send email using AJAX and PHP but no success:( My
I am trying to send email using smtp authentication through google but I am
I'm trying to send an email via some C# ASP.NET code. This is being
I can't figure out why this isn't working. I'm trying to send an email
I am trying to send notification emails(which is working fine) but have added the
I'm trying to send an email using SmtpClient.try_send(). This code used to work before
I'm trying to send an email with custom headers but for some reason they
I've been trying to send an email from my magento module but for some
i am trying to send PDF file using itextsharp , the email sends fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.