I have done all the setting, I tried hit and trial, specified IP etc but still I am unable to send mail from my c# code (outside my domain, within its fine).
If I try to send mail by specifying credentials in web config, then I am able to send mails outside my domain. But that is not I want.
When I try to send via my code, then I do the setting on the SMTP , allow relay and specify domain, that doesn't work.
I check the checkbox, which states that send mail to all address etc. That is also not working.
Where I am wrong?
My code:
When I specify in web config:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network enableSsl="false" host="hostname" port="25" userName="abc" password="abc#" defaultCredentials="false" clientDomain="domainname"/>
</smtp>
</mailSettings>
When specifying through code:
using (smtp)
{
smtp.Host = "hostname";
smtp.UseDefaultCredentials = false;
smtp.Port = 25;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "abc123#");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
}
These settings in the server, but no success.
Copyright Notice:Content Author:「Incredible」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18982041/unable-to-send-mail-mail-relay-error-have-all-settings-in-smtp-mail-server