Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to send an email from my domain address in C#, but I get an error.

This is my code:
C#
var smtp = new SmtpClient
{
      Host = "webmail.myDomain.gov.sa",
      Port = 25,
      EnableSsl = true,
      DeliveryMethod = SmtpDeliveryMethod.Network,
      UseDefaultCredentials = false,
      Credentials = new NetworkCredential("test@myDomain.gov.as", "12345678")
 };

var smtp = new SmtpClient
            {
                Host = "webmail.myDomain.gov.sa",
                Port = 25,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential("test@myDomain.gov.as", "12345678")
            };

            var mess = new MailMessage(senderAddress, receiverAddress)
            {
                Subject = message.Subject,
                Body = message.Body,
                IsBodyHtml = true
            };

            if (isAttach)
            {
                mess.Attachments.Add(new Attachment(message.Attachment));
            }

            smtp.Send(mess);


I get this error:
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 91.195.89.155:25


What I have tried:

I think it is because of security issue in host server maybe?
Posted
Updated 19-Oct-23 4:59am
v2
Comments
Richard MacCutchan 19-Oct-23 3:43am    
"I think it is because of security issue in host server maybe ?"
In which case you need to check with the provider, to see what their security requirements are.

We can't help: you need to contact the email hosting provider and ask them.
Fixing this needs access to your host settings including your username and password which (I assume) we do not have (and if we do, you need to change them immediately).
 
Share this answer
 
The error message you received indicates that the connection attempt to the SMTP server failed. There could be several reasons like firewall, network, SMTP configuration or credential issue. Try to verify each of these potential issues to determine the root cause of the problem.

You can also test the connection manually using tools like Telnet or any smtp test tool (like gmass, dnschecker.org) to check if you can establish a connection to the SMTP server. If the issue persists, consider contacting the administrator or support for the SMTP server for further assistance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900