Solved

Code to stop Unable to Relay message for email

Posted on 2012-04-04
8
338 Views
Last Modified: 2012-06-21
Hi
I have the code below, which works fine for sending internal email. Works on a PC.
But for external email, I get the message:
Mailbox unavailable. The server response was: 5.71. unable to relay
I've searched online, but the solutions seem to involve making changes on the exchange server. Is there a way I can add settings through code to fix this issue?


Dim smtp As New SmtpClient("mymailservername")
Dim mailClient As New MailMessage()

  With mailClient
            .From = New MailAddress(TM_FROM)
            .To.Add(stAgent_Email)
            .Subject = stSubject
            .Body = stBody
         End With

         'send the message
         smtp.Send(mailClient)

Open in new window

0
Comment
Question by:jdhackett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 26

Expert Comment

by:Tony Johncock
ID: 37805314
Afraid you need to change the permissions on the Exchange server.

This is by design to stop viruses, rogue programs etc doing exactly this - using your server as an open relay and spamming.
0
 
LVL 1

Author Comment

by:jdhackett
ID: 37805325
Ok, can you tell me how to change the permissions on the Exchange server so? Its Exchange 2010, I can't find the "SMTP Virtual Server" that the online help refers to.
0
 
LVL 26

Expert Comment

by:Tony Johncock
ID: 37805337
Here you go:

http://msexchangeteam.com/archive/2006/12/28/432013.aspx

I generally utilise a new connector.

By the way - I realise it's for 2007 but it's valid for 2010 too.
0
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
LVL 1

Author Comment

by:jdhackett
ID: 37805386
Followed those instructions, added the IP of my PC, used Option 1. Still getting the same problem though. Any other ideas?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37805430
0
 
LVL 26

Accepted Solution

by:
Tony Johncock earned 500 total points
ID: 37805455
Hmm it should work - I've used it myself several times.

But i've usually granted the anonymous permission too.

Indeed, there's actually an updated article the suggests it's the preferred method:

http://technet.microsoft.com/en-us/library/bb232021.aspx

CodeCruiser - your method would bypass the Exchange server, therefore bypassing things like message tracking.
0
 
LVL 1

Author Comment

by:jdhackett
ID: 37805460
Working now! I was still trying to figure it out, when I tried again and it worked. I think there must be a 10 minute delay between setting it up on the mail server and it actually working?

Either way, all good to go now, thank you.
0
 
LVL 26

Expert Comment

by:Tony Johncock
ID: 37805464
Ah good - I've never noticed a delay quite that long before but good to know you got it running :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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