I am setting up a function to send out mails(as confirmation for orders but thats a later matter).
Problem is that the mails are to be sent from the companys exchange server and so far all i have gotten is connection failed.
I am in communication with the server tech trying to find out whats wrong, and since its been a while since i set up email(on the cms side) i might be making a stupid mistake, so maybe somebody here will catch it :)
web.config: (port number specified by server tech)
(all info replaced with generic but consistent names for safety ofc)
<system.net>
<mailSettings>
<smtp from="info@mydomain.com">
<network host="smtp.ourexchangeserver.dk" userName="info@mydomain.com" password="secret" port="26" />
</smtp>
</mailSettings>
razor script test:
@{
try {
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("myadress@gmail.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("info@mydomain.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Send(message);
}
catch(Exception ex)
{
<p> error: <br/> @ex.ToString() </p>
}
}
Error caught in exception:
System.Net.Mail.SmtpException: Failure sending mail. --->
System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Thank you in advance.