Solved

Error while sending an email form my website with SmtpClient.

Posted on 2009-05-14
8
1,304 Views
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 "info@sharplabelcutter.com"  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 =  "myemail@yahoo.com";

 string mailTo =      "freind_email@yahoo.com";;

        

        System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage("contact@sharplabelcutter.com", 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("contact@sharplabelcutter.com", "my_password", "webmail.sharplabelcutter.com");

        //mailClient.Host = "";

        mailClient.Port = 25;

        mailClient.UseDefaultCredentials = false;

        mailClient.Credentials = basicAuthenticationInfo;
 

        try

        {

            mailClient.Send(email);

        }

        catch (Exception ex)

        {

           return ex.string();

        }

Open in new window

0
Comment
Question by:Elham_Seif
8 Comments
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 100 total points
Comment Utility
you will surely find your solution from http://www.systemnetmail.com/
0
 
LVL 8

Assisted Solution

by:Faheem Shaikh
Faheem Shaikh earned 100 total points
Comment Utility
Have a look here for some causes and resolutions of this:
http://www.mailenable.com/kb/Content/Article.asp?ID=me020390
 
0
 
LVL 6

Accepted Solution

by:
Ramone_Hamilton earned 300 total points
Comment Utility
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.
0
 

Author Comment

by:Elham_Seif
Comment Utility
Hi
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.
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 6

Expert Comment

by:Ramone_Hamilton
Comment Utility
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("smtp1.myhost.com");
0
 

Author Comment

by:Elham_Seif
Comment Utility
Hi Ramone_Hamilton
my host is www.sharpLabelCutter.com.
what should I write instead of "smtp1.myhost.com" in the code you said?
0
 
LVL 6

Expert Comment

by:Ramone_Hamilton
Comment Utility
Are you running your own smtp service or is your web page being hosted by another company?
0
 

Author Comment

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

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

There was an incident about the POP3 issue for the double read receipts and delivery receipts in Exchange 2013.  There was huge research been done and found solution for the duplicate mails. Especially when the user gets  duplicate mails.
Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In this video we show how to create an Accepted Domain 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 Mail Flow >> Ac…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now