Why does my mail script throw an 'unable to relay' exception on Exchange?

I have a form on our website that handles emails.  Instead of having traditional mailto links, we have linkbuttons that direct to a form that sends the email.  It's a spam thing.  Anyway, this all worked beautifully before we deployed our new Exchange mail server last week.  Now when someone enters an address OUTSIDE our domain in the CC: field, the mail server says "550 5.7.1 Unable to relay..."  All I did was change the old mail server to the new one in the SmtpMail.SmtpServer setting.

The code is below.  I have commented out the try...catch block so that I can see the error message instead of my error page.  If you want to try the form, go here: http://www.co.frederick.va.us/apps/email_form/email_form_2.aspx?user=webmastr.  

What do I have to do to make this work with our Exchange server?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Web.Mail;
 
namespace email_form
{
    public partial class _Default : System.Web.UI.Page
    {
 
        // Global variables.
        string strDomain;
        string strResult;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string strEmailUser = Request["user"].ToString();
                if (strEmailUser != null)
                {
                    if (strEmailUser.Contains("@"))
                    {
                        strResult = strEmailUser;
                    }
                    else
                    {
                        strDomain = "@co.frederick.va.us";
                        strResult = strEmailUser + strDomain;
                        // lblTestSession.Text = strResult;
                    }
                }
                if (strEmailUser == "")
                {
                    // lblTestSession.Text = "No data!";
                    Response.Redirect("problem_variable.aspx");
                }
            }
            catch (Exception ex1)
            {
                Response.Redirect("problem_variable.aspx");
            }
        }
 
        protected void btnSend_Click(object sender, EventArgs e)
        {
            MailMessage objMail0 = new MailMessage();
 
            // Initial setup.
            objMail0.To = strResult;
            objMail0.Cc = Server.HtmlEncode(txtCC.Text);
            string strCC = txtCC.Text;
            objMail0.From = Server.HtmlEncode(txtSenderEmail.Text);
            string strFromEmail = Server.HtmlEncode(txtSenderEmail.Text);
            string strFromName = Server.HtmlEncode(txtSender.Text);
            objMail0.Headers.Add("Reply-To", Server.HtmlEncode(txtSenderEmail.Text));
            objMail0.BodyFormat = MailFormat.Text;
            objMail0.Priority = MailPriority.Normal;
            objMail0.Subject = Server.HtmlEncode(txtSubject.Text);
            string strToday = DateTime.Now.ToString();
            string strIPAddress = Request.ServerVariables["remote_addr"];
            //System.Net.IPHostEntry host = new System.Net.IPHostEntry();
            //host = System.Net.Dns.GetHostByAddress(Request.ServerVariables["REMOTE_HOST"]);
            //string strMachineName = host.HostName;
            string strMessage = Server.HtmlEncode(txtMessage.Text);
 
            //Format the email.
            objMail0.Body = "**This message was sent via the website email form.**" +
                            "\r\n\r\nSender: " + strFromName +
                            "\r\nEmail: " + strFromEmail +
                            "\r\nIP address: " + strIPAddress + 
                            //"\r\nHost: " + strMachineName + 
                            "\r\nDate: " + strToday + 
                            "\r\nCC: " + strCC +
                            "\r\n\r\nMessage: " + "\r\n" + strMessage
                            ;
 
            //Send the email. 
            SmtpMail.SmtpServer = "fcmail.co.frederick.va.us";
            //try
            //{
                SmtpMail.Send(objMail0);
            //}
           // catch (Exception ex)
            //{
            //    Response.Redirect("problem.aspx");
            //}
 
            Session.Remove("emailUser");
            Response.Redirect("thanks.aspx");
            
        }
    }
}

Open in new window

mrcoulsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrcoulsonAuthor Commented:
PS Please tell me the answer does not involve rewriting the entire thing with System.Net.Mail!

Jeremy
0
Rick FeeMessaging Engineer - Disaster Recovery EngineerCommented:
Sounds like all you have to do is setup email relay for the IP of your webmail server.    Is this Exchange 2007?     Be careful with this if the webserver is external.   You don't want to allow spammers to relay off you.

How to setup relaying in Exchange 2007:
http://msexchangeteam.com/archive/2006/12/28/432013.aspx 
0
ryan80Commented:
In the relaying, you can set it so only specific IP's are allowed to relay, so you should be able to just add the IP address of your web server.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

mrcoulsonAuthor Commented:
Actually, guys, it was just SMTP authentication!  The network administrator is quite a hawk, so I assumed he had locked it down well.  I just needed to create an account that can authenticate to send these messages.

Jeremy
0
mrcoulsonAuthor Commented:
By the way, the final solution is below.
0
mrcoulsonAuthor Commented:

objMail0.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");	//basic authentication
            objMail0.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "user"); //set your username here
            objMail0.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "pass");	//set your password here
            SmtpMail.SmtpServer = "fcmail.co.frederick.va.us";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ryan80Commented:
yup, that would definitly help.
0
mrcoulsonAuthor Commented:
Yeah, Exchange is brand new to me.  Sorry for wasting everyone's time with an easy one!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.