[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2010-08-17
10
Medium Priority
?
3,517 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
[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
  • 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
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 

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
 
LVL 10

Accepted Solution

by:
Jini Jose earned 1000 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 1000 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

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
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.

650 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