Reputation: 12709
i'm using MailMessage class to send emails
MailMessage msg = new MailMessage(fromAddr, toAddr);
when i create the new MailMessage object it automatically gets the host using the fromAddr.for an example,if my fromaddress is [email protected] it assumes the host as pindoc.com.au but i have a different name for the host.so the host name is wrong.i think because of that i'm getting the following error.
{"Mailbox unavailable. The server response was: 5.7.1 Unable to relay"} System.Exception {System.Net.Mail.SmtpFailedRecipientException}
how can i solve this?
Upvotes: 1
Views: 3565
Reputation: 13141
Typically, i'll use SmtpClient to send messages. It's constructor takes a host and port:
SmtpClient mailClient = new SmtpClient("mail.domain.com", 25);
mailClient.Send(msg);
Upvotes: 0
Reputation: 9503
you can specify the mail server when you create an instance of the SmtpClient object (as well as other details like port numbers and authentication)
SmtpClient client = new SmtpClient("different.hostname"); // specify your hostname
client.Send(msg);
You could also specify your smtp details in the web.config or app.config and the SmtpClient will pick these up automatically...
SmtpClient client = new SmtpClient();
client.Send(msg);
Upvotes: 1
Reputation: 21127
Have you checked your mailSettings
? Example web.config below:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network defaultCredentials="true" host="mail.yourdomain.com" port="25"/>
</smtp>
</mailSettings>
</system.net>
Upvotes: 3