• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3644
  • Last Modified:

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

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
kathysmith
Asked:
kathysmith
  • 5
  • 3
  • 2
2 Solutions
 
Jini Jose.Net Team LeadCommented:
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
 
kathysmithAuthor Commented:
NOTE: the values in the "to" and "from" fields do not contain yahoo, gmail or hotmail.
0
 
Jini Jose.Net Team LeadCommented:
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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
kathysmithAuthor Commented:
@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
 
kathysmithAuthor Commented:
I've tested sending of email with values as someName@company.com in the "to" and "from" fields. But it doesn't work.
0
 
Jini Jose.Net Team LeadCommented:
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
 
ultrawebsitesCommented:
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
 
kathysmithAuthor Commented:
@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
 
ultrawebsitesCommented:
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
 
kathysmithAuthor Commented:
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now