Solved

ASP.NET send email - "Mailbox unavailable. The server response was: 5.7.1 Unable to relay" error

Posted on 2010-08-17
10
2,670 Views
Last Modified: 2012-05-10
Hei!

I've implemented an ASP.NET (C#) application which has a send email functionality. The code works well when running from Visual Studio IDE against my localhost. When running on the staging web server, I'm getting the following error message:

Mailbox unavailable. The server response was: 5.7.1 Unable to relay for someName@domainName.com

(where someName@domainName.com is the email address in the "to"-field)

Implementation details:
web.config:
<mailSettings>
  <smtp>
    <network host="hostName" port="25"/>
  </smtp>
</mailSettings>

Open in new window


simplified code sequence (which also gives the error mentioned above):
public static void SendEmail(string server)
{
string to = "jane@contoso.com";
string from = "ben@contoso.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Some subject";
message.Body = @"Some body";
SmtpClient client = new SmtpClient();
client.Send(message);
}

Open in new window


Other details:
- the hostName and port value in web.config are the values I've got from the system administrator (SA)
- there is no Default SMTP Virtual server on our IIS (which is an IIS6)
- SA does not want to install a Default SMTP Virtual server on IIS
- SA wants that the emails sendt by web applications use the hostName and port value in the web.config
- SA says I don't need a special username and password for seding email

What I tried:
- added deliveryMethod="Network": <smtp deliveryMethod="Network">
- changed to: <network host="hostName" port="25" defaultCredentials="true"/>
None of these helped.

QUESTION
- what settings/code do I need in order to solve this problem?

I've seen the error message quite a lot on Internet, but I haven't found the right solution for my scenario.
0
Comment
Question by:kathysmith
  • 5
  • 3
  • 2
10 Comments
 
LVL 10

Expert Comment

by:Jini Jose
ID: 33459108
you need smtpcredentials to send mail

refer the below code

private static void SendThroughSMTP(MailMessage msg)

    {

        SmtpClient Smtp = new SmtpClient();

        System.Net.NetworkCredential SmtpUser = new System.Net.NetworkCredential();

        //--Build Message



        //'--Define AuthenticatedUser;

        SmtpUser.UserName = "SMTPUser";

        SmtpUser.Password = "SMTPPassword";

        SmtpUser.Domain = "SMTPServer";

        //'--Send Message

        Smtp.UseDefaultCredentials = false;

        Smtp.Credentials = SmtpUser;

        Smtp.Host = "SMTPServer";

        Smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

        Smtp.Send(msg);

    }

Open in new window

0
 

Author Comment

by:kathysmith
ID: 33459113
NOTE: the values in the "to" and "from" fields do not contain yahoo, gmail or hotmail.
0
 
LVL 10

Expert Comment

by:Jini Jose
ID: 33459139
that is great !!. if your server cannot send mails to yahoo, gmail or hotmail then it is interesting that who else can you able to send. i think there is nothing remaining.
I think it is only "from" fields do not contain the listed domains.
0
 

Author Comment

by:kathysmith
ID: 33459280
@gmailjini: thanx for quick answer. But, as I wrote: "SA says I don't need a special username and password for seding email". So?
0
 

Author Comment

by:kathysmith
ID: 33459319
I've tested sending of email with values as someName@company.com in the "to" and "from" fields. But it doesn't work.
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 10

Accepted Solution

by:
Jini Jose earned 250 total points
ID: 33459327
normally for sending smtp mail userid and password is not required. but  now a days spam is very high. so the smtp server is now asking for  these. if you use the these, they mails you send will never go to spams.

you will get the details in the following link

http://forums.asp.net/t/966344.aspx

0
 
LVL 4

Assisted Solution

by:ultrawebsites
ultrawebsites earned 250 total points
ID: 33468389
Also,
- maybe your SA can enable relaying on the SMTP server from your webserver
- try sending 'from' your website's domain name, but 'to' a different domain name. This can often cause a problem, having the 'to' the same as the 'from'.

HTH
Matt
1
 

Author Comment

by:kathysmith
ID: 33469487
@ultrawebsites: before I posted the question I tried sending with different "to" and "from" addresses, as you suggested, but it didn't help.

The conclusion: our SA should enable relaying on the SMTP server, eventually assign credentials that I can use further in my code.

Thank you both for answers. I'll share the points between you two, since both of you helped me.

0
 
LVL 4

Expert Comment

by:ultrawebsites
ID: 33469755
Hi there
SMTP can certainly be a pain to configure. FYI, specifically, whilst 'to' and 'from' should typically be different, in the instance I'm thinking of, it is important that the 'from' address is the same domain as the website. ie. the website SMTP settings et al only permit you to send email from the domain name that the code is running from, as per security settings.
HTH
Cheers
Matt
0
 

Author Comment

by:kathysmith
ID: 33602330
Hi everybody!

My problem has been solved, and the solution has been worked well since. The solution is:
1. No "Default SMTP Virtual server" has been installed on our IIS (we have IIS6 on test environment and IIS7 on production).
2. In web.config, the only thing you need is:
3. The method that performs the sending is the same as I mentioned in my question.
4. The system administrator has configure the MS Exchange server. Unfortunately, I don't know how he did it.
After all these 4 steps, everything works.

<mailSettings>

  <smtp>

    <network host="hostName" port="25" defaultCredentials="true"/>

  </smtp>

</mailSettings>

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

747 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