i written a simple code
SmtpClient smtp = new SmtpClient(“localhost”);
smtp.Send(“firstname.lastname@example.org”, “email@example.com”, “Test mail subject”, “Test mail body”);
but got exception “Mailbox unavailable. The server response was: 5.7.1 Unable to relay firstname.lastname@example.org.”. Problem is not in the code problem is in the configuration of localhost. It considers itself being used as a mail relay and by default it does not allow anyone to do that. It is easy to solve.
1. Go to “Default SMTP Virtual Server” in IIS and then go to properties
2. Select tab “Access”
3. Add ip of localhost “127.0.0.1”