SMTP server Unable to relay for [email]

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2009
Posts: 10
Reputation: MatthewKeyzer is an unknown quantity at this point 
Solved Threads: 0
MatthewKeyzer MatthewKeyzer is offline Offline
Newbie Poster

SMTP server Unable to relay for [email]

 
0
  #1
Aug 25th, 2009
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.

  1. public static void SendMailQ(MailMessage Message)
  2. {
  3. SmtpClient cli = new SmtpClient("172.16.252.8");
  4.  
  5. bool useAuth = false;
  6. string userName = string.Empty;
  7. string password = string.Empty;
  8. string authDomain = string.Empty;
  9. NetworkCredential cred = null;
  10. cli.UseDefaultCredentials = false;
  11.  
  12. cli.UseDefaultCredentials = false;
  13.  
  14. if (string.IsNullOrEmpty(authDomain))
  15. {
  16. cred = new NetworkCredential(userName, password);
  17. }
  18. else
  19. {
  20. cred = new NetworkCredential(userName, password, authDomain);
  21. }
  22.  
  23. cli.Credentials = cred;
  24.  
  25.  
  26. cli.Send(Message); //////bombs out here


can anybody help? have i missed out something?
Last edited by John A; Aug 26th, 2009 at 12:30 am. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,442
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 626
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: SMTP server Unable to relay for [email]

 
0
  #2
Aug 25th, 2009
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]
Last edited by sknake; Aug 25th, 2009 at 6:57 am.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: MatthewKeyzer is an unknown quantity at this point 
Solved Threads: 0
MatthewKeyzer MatthewKeyzer is offline Offline
Newbie Poster

Re: SMTP server Unable to relay for [email]

 
0
  #3
Aug 25th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,442
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 626
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: SMTP server Unable to relay for [email]

 
0
  #4
Aug 25th, 2009
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
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: MatthewKeyzer is an unknown quantity at this point 
Solved Threads: 0
MatthewKeyzer MatthewKeyzer is offline Offline
Newbie Poster

Re: SMTP server Unable to relay for [email]

 
0
  #5
Aug 25th, 2009
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....
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,442
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 626
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: SMTP server Unable to relay for [email]

 
0
  #6
Aug 25th, 2009
Try this and tell me if it works:
  1. public static void SendMailQ(MailMessage Message)
  2. {
  3. SmtpClient cli = new SmtpClient("172.16.252.8");
  4. cli.UseDefaultCredentials = false;
  5. cli.Credentials = null;
  6. cli.Send(Message);
  7. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: MatthewKeyzer is an unknown quantity at this point 
Solved Threads: 0
MatthewKeyzer MatthewKeyzer is offline Offline
Newbie Poster

Re: SMTP server Unable to relay for [email]

 
0
  #7
Aug 25th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,442
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 626
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: SMTP server Unable to relay for [email]

 
0
  #8
Aug 25th, 2009
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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: MatthewKeyzer is an unknown quantity at this point 
Solved Threads: 0
MatthewKeyzer MatthewKeyzer is offline Offline
Newbie Poster

Re: SMTP server Unable to relay for [email]

 
0
  #9
Aug 25th, 2009
no tried that code and still got the User Unknown error...
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: MatthewKeyzer is an unknown quantity at this point 
Solved Threads: 0
MatthewKeyzer MatthewKeyzer is offline Offline
Newbie Poster

Re: SMTP server Unable to relay for [email]

 
0
  #10
Aug 25th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1145 | Replies: 13
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC