Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# SMTP authentication error 2

Status
Not open for further replies.

akgta

Programmer
Jul 18, 2007
42
CA
Hello,

I am getting the following SMTP Authentication error message, when I am trying to send an email using the following C# script:

Error: The server response was: 5.7.1 Unable to relay

Code:
    private void send_emails()
    {

     System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

        message.To.Add("recepient@test.com");
        message.Subject = "Test Subject";
        message.From = new System.Net.Mail.MailAddress("sender@test.com");
        message.Body = "Test Body";

        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.servername.com");
  
        smtp.Send(message);
     }

So I did some search and the conclusion is that I also need to specify the smtp username and password for authentication.

How can this be achieved

Thanks in advance.
 
Where is your app hosted?

Some hosts (probably most) will not allow smtp mails to be sent from a location other than their server. So are you trying to send the mail from the "debug" mode on localhost, or from the web server itself?

Your code may not work when you run it locally, but work just fine when deployed to your server.

Hope this helps,

Alex

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top