Fail to send Email through my Domain Name

mostafa ahmed 41 Reputation points
2023-10-19T07:05:42.15+00:00

I want to send an Email from my domain address in C#, but I get this error

This is my code:

var smtp = new SmtpClient
{
      Host = "webmail.myDomain.gov.sa",
      Port = 25,
      EnableSsl = true,
      DeliveryMethod = SmtpDeliveryMethod.Network,
      UseDefaultCredentials = false,
      Credentials = new NetworkCredential("******@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("******@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);


But 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
.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,103 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,815 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,598 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,407 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 74,531 Reputation points
    2023-10-20T15:24:27.7033333+00:00

    Most like the connection information is wrong. Port 25 is seldom used anymore.

    note: SmtpClient does not support oauth authentication which is becoming standard.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.