The program runs on multiple computers within the same network. The mail is sent through an internal server. When I try to send an email from SmtpClient, it works on some computers but on others it gives me:
"System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 10.1.0.74:25"
I've tried looking it up and a lot of answers talk about the firewall or the smtp server blocking requests. The problem is it only errors on certain computers, and I'm unsure what the firewall settings are supposed to be.
The code for sending the email is as follows:
public void SendMessage(string subject, string messageBody, string fromAddress, string toAddress)
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient("10.1.0.74", 25);
// Set the sender's address
message.From = new MailAddress(fromAddress);
// Allow multiple "To" addresses to be separated by a semi-colon
if (toAddress.Trim().Length > 0)
{
foreach (string addr in toAddress.Split(';'))
{
if (addr.Trim() != "")
message.To.Add(new MailAddress(addr));
}
}
// Set the subject and message body text
message.Subject = subject;
message.Body = messageBody;
message.IsBodyHtml = true;
// Set the SMTP server to be used to send the message
//client.Host = "smtp.gmail.com";
System.Net.NetworkCredential a = new System.Net.NetworkCredential("User", "Pass");
//client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = a;
// Send the e-mail message
client.Send(message);
}
Edit: Pinged the IP from the computer that's not working, got the following.