Error while sending an email form my website with SmtpClient.

Posted on 2009-05-14
Last Modified: 2013-12-17
I'm developing a website with ASP.NET 2005 and C#. I tried to send emails from my website
using the code I put in code section.
it gives me the follwing error:
"Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server"
If I change the mairTo to ""  which is my website, it'll work fine. But this way I can only send emails to my own website.!
Please help me how to solve my problem.
string mailFrom =  "";
 string mailTo =      "";;
        System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage("", mailTo);
        email.Subject = "subject";
        email.IsBodyHtml = true;
        email.Body = " body of the email";
        System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
        System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("", "my_password", "");
        //mailClient.Host = "";
        mailClient.Port = 25;
        mailClient.UseDefaultCredentials = false;
        mailClient.Credentials = basicAuthenticationInfo;
        catch (Exception ex)
           return ex.string();

Open in new window

Question by:Elham_Seif
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 100 total points
ID: 24384174
you will surely find your solution from

Assisted Solution

by:Faheem Shaikh
Faheem Shaikh earned 100 total points
ID: 24384430
Have a look here for some causes and resolutions of this:

Accepted Solution

Ramone_Hamilton earned 300 total points
ID: 24384612
Are you using your own smtp server?  If so check to make sure that it is capable of sending e-mails outside of your domain.  I believe that most webmails such as hotmail, yahoo or gmail won't accept your e-mails unless they are coming from a legit exchange or smtp server connected to a static ip address.
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Comment

ID: 24385627
I got confused reading those long sites about emails.
Would you please read my code and tell me what's wrong with the code?
What can I use instead, to make it run correctly.
The one that can correct my code will get the points.
Thanks in advance.

Expert Comment

ID: 24385753
You haven't set the address of the smtpclient you are sending from.  Try this:

System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("");

Author Comment

ID: 24386458
Hi Ramone_Hamilton
my host is
what should I write instead of "" in the code you said?

Expert Comment

ID: 24386804
Are you running your own smtp service or is your web page being hosted by another company?

Author Comment

ID: 24401179
Hi Ramone_Hamilton
My website is hosted by another company.
How can I run my won smtp service? And what's the diffrence?

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question