smtp exception Failure sending mail?

smtp exception failure sending mail powershell
failure sending mail. c# smtpclient gmail
system.net.mail.smtpexception failure sending mail unable to connect to the remote server
failure sending mail in asp.net c#
failure send mail c# smtp yahoo
system.net.mail.smtpexception failure sending mail unable to read data from the transport connection
failure sending mail gmail smtp
invalidoperationexception failure sending mail
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: 

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);

smtp exception “failure sending mail”, It's likely that you're actually getting this error, it's just suppressed in some way by you being in a console app. The SMTP server requires a  I am making an SMTP mail application with C#.Net. It is working ok for Gmail settings, but I have to work it for a connection to VSNL. I am getting an exception: "Failure sending mail" My settings

First, you don't need to manually read the values in your .config file. You can set the in the System.Net section and your SmtpClient object will read them automatically:

<system.net>
    <mailSettings>
      <smtp from="Sender's display name &lt;sender_email@domain.com&gt;">
        <network host="mailserver.yourdomain.com" port="25" userName="smtp_server_username" password="secret" defaultCredentials="false" />
      </smtp>
    </mailSettings>
  </system.net>

Then, from your code, you just write:

        SmtpClient smtp = new SmtpClient();
        MailMessage mailMessage = new MailMessage();
        mailMessage.To.Add(new MailAddress("recipient@somedomain.com", "Recipient Display Name"));
        mailMessage.Subject = "Some Subject";
        mailMessage.Body = "One gorgeous body";
        smtp.Send(mailMessage);

Coming back to your error, it would appear you have some kind of a network problem.

Sending Mail Failure using {System.Net.Mail.SmtpException , Without your code to check how you are doing it, we can't rally help much. However, this works: Sending an Email in C# with or without  Well, with the PickupDirectoryFromIis set, the EML file is saved into the directory from which IIS picks up the e-mails to send. You still can test this by changing your local smtp configuration: IIS-> default SMTP server -> properties -> delivery -> advanced and then you can set up the smart host to be your 3d party IP address.

I suggest you the simplest way to send email on exception - using Elmah. Please follow this guide line for the solution: https://www.stormconsultancy.co.uk/blog/development/tools-plugins/setup-email-alerts-from-elmah-when-exceptions-are-raised/

'System.Net.Mail.SmtpException: Failure sending mail., 'System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.​IOException: Unable to read data from the transport connection:  123.hp.com provide 123 HP Printer setup guidelines, easy driver software installation, any troubleshooting steps for all your envy, officejet, officejet pro, deskjet printer models.

try
           {
               MailMessage mail = new MailMessage();
               //SmtpClient SmtpServer = new SmtpClient("smtp.google.com");
              SmtpClient SmtpServer = new SmtpClient(sServer);

              // SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com", 587);
               mail.From = new MailAddress(sFromEmailId);
               mail.To.Add(sToEmailId);
               mail.Subject = sSubject;
               mail.Body = sMessage;
               mail.IsBodyHtml = true;             
               HttpFileCollection hfc = Request.Files;
               for (int i = 0; i < hfc.Count; i++)
               {
                   HttpPostedFile hpf = hfc[i];
                   if (hpf.ContentLength > 0)
                   {
                       mail.Attachments.Add(new Attachment(fupload.PostedFile.InputStream, hpf.FileName));

                   }
               }
               SmtpServer.Port = 587;
               //SmtpServer.Host = "smtp.gmail.com";
               SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
               SmtpServer.UseDefaultCredentials = false;
               SmtpServer.Credentials = new System.Net.NetworkCredential(sFromEmailId, sPassword);
               SmtpServer.EnableSsl = true;
               SmtpServer.Send(mail);                
               ClientScript.RegisterStartupScript(this.GetType(), "Alert", "dim('Mail Sent Successfully..!');", true);
               mail.Dispose();
           }
           catch (Exception ex)
           {                
               ClientScript.RegisterStartupScript(this.GetType(), "Alert", "dim('Error in Sending Mail..!');", true);
           }

System.Net.Mail.SmtpException: Failure sending mail. (Trying to , SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. Represents the exception that is thrown when the SmtpClient is not able to complete a Send or SendAsync operation. public ref class SmtpException : Exception [System.Serializable] public class SmtpException : Exception type SmtpException = class inherit Exception interface ISerializable Public Class SmtpException Inherits Exception.

Another reason for this exception could be the anti virus installed on your system. This may be prohibiting the application to send mails. Just look out for a dialog box that is asking for permission to send mails through an application on your system.

Failure sending mail, Message: Failure sending mail. Exception type: System.Net.Mail.SmtpException Stack trace: at System.Net.Mail.SmtpClient.Send(MailMessage  Another reason for this exception could be the anti virus installed on your system. This may be prohibiting the application to send mails. Just look out for a dialog box that is asking for permission to send mails through an application on your system.

SMTP Problems - failure sending mail., Message: System.Net.Mail.SmtpException: Failure sending mail. Send(​MailMessage message) --- End of inner exception stack trace --- at  Usually indicates an issue with sending the email through the specified SMTP host (ie. the message was rejected, connection closed, host not found etc.). Are you sure that domain.com is the correct smtp server fqdn and that you're allowed to send mails through it anonymously?

SmtpClient.Send Method (System.Net.Mail), Sends an email message to an SMTP server for delivery. SmtpException can also contain an inner exception that indicates the reason the operation failed. Instead of throwing the exception right away, why not try sending the mail again? If there is a problem of any kind at the SMTP server level, the server reports an exception, you will probally use SmtpException to handle this. While using the SmtpException works well, its functionality is limited in determining exactly how the send failed.

Failure sending mail, Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to Mail.SmtpClient.Send(MailMessage message) --- End of inner exception  When sending email using Send to multiple recipients and the SMTP server accepts some recipients as valid and rejects others, Send sends email to the accepted recipients and then a SmtpFailedRecipientsException is thrown (or a SmtpFailedRecipientException if only one recipient is rejected).

Comments
  • The server might probably be listening on port 587
  • {"No connection could be made because the target machine actively refused it 125.63.68.148:587"} getting this as a part of my inner execption
  • @vini: Also check if your antivirus blocks sending mails from the application
  • {"Mailbox unavailable. The server response was: 5.7.1 Unable to relay"} i get this now {"Unable to send to all recipients."}
  • this error - {"Mailbox unavailable. The server response was: 5.7.1 Unable to relay"} i get this now {"Unable to send to all recipients."} can be solve by adding your machine/server IP under the "relay" section of SMTP settings