i am currently trying to configure a email sending function using an SMTP server.

when i send a mail to and from a person with the email extension of @dtss.com (The company employes) it works perfectly with attachments and everything

if i change the ToAddress to anything else (i.e. matthew@crimzone.com) it gives me this error: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for matthew@crimzone.com

ive search forums and turned relaying on, allow anonymous on authentification and enabled logging... it still doesnt work

this is the code:

the message details are determined in another method and that works fine. Username and password is null.

public static void SendMailQ(MailMessage Message)
        {
            SmtpClient cli = new SmtpClient("172.16.252.8");
          
            bool useAuth = false; 
            string userName = string.Empty; 
            string password = string.Empty; 
            string authDomain = string.Empty; 
            NetworkCredential cred = null;
            cli.UseDefaultCredentials = false;
           
            cli.UseDefaultCredentials = false;
           
            if (string.IsNullOrEmpty(authDomain))
            {
                cred = new NetworkCredential(userName, password);
            }
            else
            {
                cred = new NetworkCredential(userName, password, authDomain);
            }
            
            cli.Credentials = cred;


            cli.Send(Message);         //////bombs out here

can anybody help? have i missed out something?

That looks like my code.... Where did you get it from? Anyways yes you did miss something. In your case you're initializing the username and password to null which will fail authentication with the server so you should just use the default credentials.

By the way -- You should never turn on anonymous relaying. You should create a user on your mailserver for the application.

Also please use code tags when posting code on daniweb:

[code=csharp] ...code here...

[/code]

Hi. Thanks for your help... so i must just use default Credentials. Looking at the code that means i take out the whole if statement and the duplicate line above it, and set the cli.UseCredentials to true. is that correct? sorry about the tags, im new here :)

Let me ask you this -- What do you want to do? Enabling relay on the mailserver is a bad idea, you should really use authentication. If you want to use anonymous relay then remove all of the user/pass/credential related code.

If you want to make a good decision ;) and use authentication then set up a user on your server and let me know and i'll post modified code

the thing is that i cant change anything on the web server... this SMTP sending function i am using works off someone else's pc for a different application. and it works(any email address)... with a private coding program that doesnt pass a username and password to the SMTP server.

i changed it so that it uses default credentials and the error states that he server response was: 5.1.1 User unknown....

Try this and tell me if it works:

public static void SendMailQ(MailMessage Message)
    {
      SmtpClient cli = new SmtpClient("172.16.252.8");
      cli.UseDefaultCredentials = false;
      cli.Credentials = null;
      cli.Send(Message); 
    }

im sorry im kind of new to working with SMTP servers. Do i have to change anything in my IIS settings? because the code refers directly to the web server?

Wait a minute here... You say it works on someone elses PC? Are you running your application from the other persons PC? You can allow "10.1.1.5" to relay anonymously but require everyone else to authenticate. There are a number of ways to punch holes in the security.

In order to test this you will have to run the application from the same PC as the current application.

no tried that code and still got the User Unknown error...

i am developing an application on my pc that refers to the SMTP server to send mail. The other guy is developing a whole new application not related to mine at all. and his app also uses the same SMTP server to send mail

im trying to get it to work. wheather or not credentials are default or null they still give that same error of cannot relay to [email].

Did you try running the application off of his machine? Just because you use the same mailserver does not mean the mailserver treats you both equally.

Get Wireshark and see how he is authenticating versus how you are authenticating and you will know what the difference is.

wot is the error u getting...could u please elaborate ..?

problem fixed. Thanks for all your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.