Solved

Code to stop Unable to Relay message for email

Posted on 2012-04-04
8
327 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
  • 4
  • 3
8 Comments
 
LVL 25

Expert Comment

by:Tony1044
Comment Utility
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
Comment Utility
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 25

Expert Comment

by:Tony1044
Comment Utility
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
 
LVL 1

Author Comment

by:jdhackett
Comment Utility
Followed those instructions, added the IP of my PC, used Option 1. Still getting the same problem though. Any other ideas?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
0
 
LVL 25

Accepted Solution

by:
Tony1044 earned 500 total points
Comment Utility
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
Comment Utility
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 25

Expert Comment

by:Tony1044
Comment Utility
Ah good - I've never noticed a delay quite that long before but good to know you got it running :-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 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

12 Experts available now in Live!

Get 1:1 Help Now