Answers

the code for sending emails is more or less always the same. It does not really matter if the application is a ASP.Net Web application, a windows Forms application of a windows service.

But we need more details what you are trying. And I am wondering: You received that error but the email arrived?

The error message "Unable to relay" simply means that the mail server saw, that the target email adress is not hosted on the SMTP server you was connected to and the server decided to not relay (which means taking the email from you and sending it further)
the message for you. This is often done by administrators to make sure their server is not missused by people who want to send SPAM.

You should check that you used the correct credentials to authenticate at the server and that you send the email exactly how the administrators allowed it and of course that you are allowed to send these emails. (So a maislerver might reject emails when
you authenticate as a user and then try to send emails with some other from address (but the common pattern I know is that the FROM: Adress is mostly replaced ...)

Maybe you wantt o give us some more details what you did to send mails.

the code for sending emails is more or less always the same. It does not really matter if the application is a ASP.Net Web application, a windows Forms application of a windows service.

But we need more details what you are trying. And I am wondering: You received that error but the email arrived?

The error message "Unable to relay" simply means that the mail server saw, that the target email adress is not hosted on the SMTP server you was connected to and the server decided to not relay (which means taking the email from you and sending it further)
the message for you. This is often done by administrators to make sure their server is not missused by people who want to send SPAM.

You should check that you used the correct credentials to authenticate at the server and that you send the email exactly how the administrators allowed it and of course that you are allowed to send these emails. (So a maislerver might reject emails when
you authenticate as a user and then try to send emails with some other from address (but the common pattern I know is that the FROM: Adress is mostly replaced ...)

Maybe you wantt o give us some more details what you did to send mails.

I have same issue: We are migrating data from SQL Server 2005 to 2012. On SQL Server 2005 I have Database mail setup and It is working fine but same I did it on SQL Server 2012 but I am getting error: "The mail could not be sent to the recipients
because of the mail server failure. (Sending Mail using Account 1 (2013-09-05T14:53:21). Exception Message: Cannot send mails to mail server. (Mailbox unavailable. The server response was: 5.7.1 Unable to relay for ram.kumar@abc.com)."

that is a mail server issue. The mail server simply refuses to forward the email (called "relaying").

Possible reasons why it worked before:

- Maybe you only sent messages where the mailbox was hosted by the server.
- Maybe the Server who sends the Emails, was changed (New IP Address or so. If the mail server admin allowed relaying for a specific IP then a changed IP would need a reconfiguration on the mail server!)
- Maybe you authenticated before and you didn't configure the authentication now.

In all cases the administrator of the mail server could help you / give you details on what to do.