Error trying to send email

1

I'm trying to send emails (using my hotmail account) and I'm encountering the error below:

  

Aconnectionattemptfailedbecausetheconnectedcomponentdidnot  responded\r\nwithaperiodoftimeortheconnection  establishedfailed\r\nbecausetheconnectedhostdidnotrespond  65.55.176.126:25

ThemethodI'musingisbelow:

publicvoidsendEMailThroughHotMail(){try{//MailMessageMailMessagemM=newMailMessage();//MailAddressmM.From=newMailAddress("[email protected]");

                //receiver email id
                mM.To.Add("[email protected]");

                //subject of the email
                mM.Subject = "your subject line will go here";

                //add the body of the email
                mM.Body = "Body of the email";

                mM.IsBodyHtml = true;

                //SMTP client
                SmtpClient sC = new SmtpClient("smtp.live.com");

                //port number for Hot mail
                sC.Port = 25;

                //credentials to login in to hotmail account
                sC.Credentials = new NetworkCredential("[email protected]", "xxxxxx");

                //enabled SSL
                sC.EnableSsl = true;

                //Send an email
                sC.Send(mM);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

I also tried sending through gmail, but Google interpreted my attempt to send as an attempt to attack ¬ ¬

    
asked by anonymous 04.11.2015 / 12:47

3 answers

2

First enter your webmail and enable POP / IMAP in hotmail setting is: Options / Connect devices and applications with POP then on the same screen you have the Other ways to connect to your inbox where you will have the settings you need to use (address, port, ssl, tls).

For gmail email, you also need to be enabled to use POP / IMAP, and there is a security configuration that also needs to be released, but I can not remember the path now. It also has the help page with the access configuration information.

    
04.11.2015 / 15:00
2

When you try to send the email on port 25 you can not have SSL enabled.

The port 25 was closed by the providers in Brazil , I do not know if this could have any problem.

But to solve your problem use SSL over port 465.

  

Example

public void sendEMailThroughHotMail()
        {
            try
            {
                //Mail Message
                MailMessage mM = new MailMessage();

                //Mail Address
                mM.From = new MailAddress("[email protected]");

                //receiver email id
                mM.To.Add("[email protected]");

                //subject of the email
                mM.Subject = "your subject line will go here";

                //add the body of the email
                mM.Body = "Body of the email";

                mM.IsBodyHtml = true;

                //SMTP client
                SmtpClient sC = new SmtpClient("smtp.live.com");

                //port number for Hot mail
                sC.Port = 465;

                //credentials to login in to hotmail account
                sC.Credentials = new NetworkCredential("[email protected]", "xxxxxx");

                //enabled SSL
                sC.EnableSsl = true;

                //Send an email
                sC.Send(mM);

            }
    
04.11.2015 / 12:58
1

Hello try this.

  protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder Body = new StringBuilder();
            Body.Append("Aqui vai meu teste vamos ver se chega!!!!! :)");


            String HostSmtp = "smtp.live.com";
            String LoginSmtp = "[email protected]";
            String PasswordSmtp = "xxxxx";
            Int32 PortaSmtp = 587;

            SmtpClient Smtp = new SmtpClient(HostSmtp, PortaSmtp);
            Smtp.UseDefaultCredentials = true;
            Smtp.EnableSsl = true;

            Smtp.Credentials = new NetworkCredential(LoginSmtp, PasswordSmtp);

            MailMessage mail = new MailMessage();
            mail.IsBodyHtml = true;
            mail.SubjectEncoding = System.Text.Encoding.UTF8;

            mail.From = new MailAddress("[email protected]");
            mail.To.Add(new MailAddress("[email protected]"));

            mail.Subject = "Teste de envio de email";
            mail.Body = Body.ToString();

            var Status = String.Empty;
            try
            {
                Smtp.Send(mail);
                Status = "Ok";
            }
            catch (Exception exc)
            {
                Status = exc.Message;
            }
        }

see the link here

    
04.11.2015 / 15:27