Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:30:09+00:00 2026-06-15T03:30:09+00:00

StringBuilder emailMessage = new StringBuilder(); emailMessage.Append(Dear Payment Team ,); emailMessage.Append(<br><br>Please find the Payment instruction);

  • 0
StringBuilder emailMessage = new StringBuilder();
emailMessage.Append("Dear Payment Team ,");
emailMessage.Append("<br><br>Please find the Payment instruction");    

try
{
    MailMessage Msg = new MailMessage();
    // Sender e-mail address.
    Msg.From = new MailAddress("pqr@gmail.com");
    // Recipient e-mail address.
    Msg.To.Add("abc@gmail.com");
    Msg.CC.Add("zcd@gmail.com");
    Msg.Subject = "Timesheet Payment Instruction updated";
    Msg.IsBodyHtml = true;
    Msg.Body = emailMessage.ToString();
    SmtpClient smtp = new SmtpClient();
    //smtp.EnableSsl = true;

    smtp.Host = ConfigurationManager.AppSettings["HostName"];
    smtp.Port = int.Parse(ConfigurationManager.AppSettings["PortNumber"]);
    smtp.Send(Msg);
    Msg = null;
    Page.RegisterStartupScript("UserMsg", "<script>alert('Mail has been sent successfully.')</script>");
}
catch (Exception ex)
{
    Console.WriteLine("{0} Exception caught.", ex);
}

Added this code in web.config

<appSettings>
    <add key="HostName"   value="The host name as given by my company" />
    <add key="PortNumber" value="25" />
</appSettings>

I keep getting an exception tried changing the port number as specified but no success

Exception Detail

  System.Net.Mail.SmtpException was caught
  Message=Failure sending mail.
  Source=System
  StackTrace:
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at PAYMENT_DTALinesfollowup.Sendbtn_Click(Object sender, EventArgs e) in d:\AFSS-TFS\AFSS\Code\ERPNET\PAYMENT\DTALinesfollowup.aspx.cs:line 488
  InnerException: System.Net.WebException
       Message=Unable to connect to the remote server
       Source=System
       StackTrace:
            at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
            at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
            at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
            at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
            at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpClient.GetConnection()
            at System.Net.Mail.SmtpClient.Send(MailMessage message)
       InnerException: System.Net.Sockets.SocketException
            Message=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 125.63.68.148:25
            Source=System
            ErrorCode=10060
            NativeErrorCode=10060
            StackTrace:
                 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
                 at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
            InnerException: 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:30:11+00:00Added an answer on June 15, 2026 at 3:30 am

    You need to give Username and password for smtp.

    Use Below code :-

        MailSettings.SMTPServer = Convert.ToString(ConfigurationManager.AppSettings["HostName"]);
        MailMessage Msg = new MailMessage();
        // Sender e-mail address.
        Msg.From = new MailAddress("pqr@gmail.com");
        // Recipient e-mail address.
        Msg.To.Add("abc@gmail.com");
        Msg.CC.Add("zcd@gmail.com");
        Msg.Subject = "Timesheet Payment Instruction updated";
        Msg.IsBodyHtml = true;
        Msg.Body = emailMessage.ToString();
        NetworkCredential loginInfo = new NetworkCredential(Convert.ToString(ConfigurationManager.AppSettings["UserName"]), Convert.ToString(ConfigurationManager.AppSettings["Password"])); // password for connection smtp if u dont have have then pass blank
    
        SmtpClient smtp = new SmtpClient();
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = loginInfo;
        //smtp.EnableSsl = true;
        //No need for port
        //smtp.Host = ConfigurationManager.AppSettings["HostName"];
        //smtp.Port = int.Parse(ConfigurationManager.AppSettings["PortNumber"]);
         smtp.Send(Msg);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I do: StringBuilder sb = new StringBuilder(); sb.append(somestring + hello + more strings
StringBuilder query = new StringBuilder(); query.Append(CREATE TABLE #Codes (Code nvarchar(100) collate database_default ) );
StringBuilder sb = new StringBuilder(); sb.Append( string.Format({0} |{1} , Name, Value) ); Display.Text =
void ExecuteContent() { StringBuilder sb = new StringBuilder(); sb.Append(SELECT TOP 1 @UsersID,u.Avatar,t.Date, u.Name, t.ThreadTitle,
StringBuilder scriptFunction = new StringBuilder(); scriptFunction.Append(<script language='javascript'>); scriptFunction.Append(alert('de')); scriptFunction.Append(</script>); ClientScript.RegisterStartupScript(GetType(), alert, scriptFunction.ToString()); This is
StringBuilder sb = new StringBuilder(); sb.Append(Line 1); //insert new line character //insert tab character
Dim sb As StringBuilder = New StringBuilder() sb.Append(<script language=javascript>) sb.Append( function SetValueInBody() {) sb.Append(
private void readIncomingMessage() { try { StringBuilder builder = new StringBuilder(); InputStream is =
I have this code: StringBuilder command = new StringBuilder(ffmpeg -ac 1 -i ); command.append(videoFile.getPath());
StringBuilder str = new StringBuilder(Today); str.append( is ).append(a).append( sunny ).append( day.); In the java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.