Bassie
Bassie

Reputation: 10400

Can only send emails when using IP of SMTP host

I have this annoying issue:

  1. When sending an email when debugging in VS, it works fine (I'm using SmtpClient)

  2. After publishing to the server, I get this error:

    System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'mail.company.co.za'

  3. However, if I change the smtp host to the IP address, it seems to work fine.

I got the IP by calling ping mail.company.co.za in CMD (When calling this on the server it can't find the address, but it can ping the IP)

Since I'm not sure whether the IP is static or not, I don't know if its safe to just use the physical IP. Why would the server not recognise the mail.company.co.za?

Note that I am debugging and hosting the application on the same network. This suggests to me that it is not a firewall issue, but maybe I'm wrong about that?

Upvotes: 0

Views: 768

Answers (1)

Robin Bennett
Robin Bennett

Reputation: 3231

That sounds like your code is working properly, but you mailserver's DNS is not set up properly. Your PC can correctly look up the address, but the mailserver cannot.

Fixing this is a server admin question, not a coding question, but if you don't have IT people to do it for you, I suggest just finding the 'DNS Server' setting in your network setup and copying the settings from your PC to the server. Windows tends to change how you get to these settings with every version, but for me it's Control Panel / Network and Sharing / Ethernet / TCPIP / Properties

https://www.windowscentral.com/how-change-your-pcs-dns-settings-windows-10

  • Open Control Panel.
  • Click on Network and Internet.
  • Click on Network and Sharing Center.
  • On the left pane, click on Change adapter settings.
  • Right-click the network interface connected to the internet, and select Properties.
  • Select Internet Protocol Version 4 (TCP/IPv4) from the list.
  • Click the Properties button.
  • Click the Use the following DNS server addresses option.

Upvotes: 1

Related Questions