Solved

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

Posted on 2010-08-17
10
3,162 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

707 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