SMTP Failed Recipient Exception - C#

In this Exception and Solution Series, today the solution to a System.Net
.Mail.SmtpFailedRecipientException
I got recently trying to send an email from a Console Application using the Smtp class from System.Net.Mail library.
Exception
System.Net
.Mail.SmtpFailedRecipientException HResult=0x80131500 Message=Mailbox unavailable. The server response was: 5.7.1 Unable to relay Source=System StackTrace: at
System.Net
.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at
System.Net
.Mail.SmtpClient.Send(MailMessage message) at <<NameOfMyConsoleApplication>>.Program.Main(String[] args) in C:\<<PathToMySolution>>\Program.cs:line 52
Solution
I just added the following system.net
configuration to my App.Config file under the <configuration>
tag
<
system.net
> <mailSettings> <smtp deliveryMethod="Network"> <network host="mail" defaultCredentials="true"/> </smtp> </mailSettings> </
system.net
>
That resolved the Exception. Thank you Vijaya Malla Vijaya Malla
Subscribe to my newsletter
Read articles from Vijaya Malla directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
