Skip to content
Loading
SMTP Server requires a secure connection or client
  • Joginder Banger
    sorry m confusion about the screen shot and code which is shared. In code mention that you are using outlook and screen shot mentioned that you are using google. Can you share the which SMTP you are using?.
     
    Note: Both are different behave and coding. 
    +1
  • Hi 
     
    Jodinger
     
    As i have seen the link, its a console application, but the question is now. I m developing MVC web application, how does this is to help me solve this problem? Its a standalone app, if i had to use it what will i have to integrate with that i am looking to achieve here? I dont know because the Authen 2 enable with one device being.
     
     
    +1
  • Joginder Banger
    Hi,
     
    could you please check below link. In this link mention that how  Create an App-Specific Password if You Have 2-Stage Auth Enabled
    so please  check.
     
    https://www.codeproject.com/Articles/700211/Csharp-SMTP-Configuration-for-Outlook-Com-SMTP-Hos 
     
    +1
  • Hi Jodinger
     
    I think you raising something i was not aware of, but kindly help the order of this logic below. Hence, Amit Gupta i do have this already set up and view my code for EnableSsl = true
    1. [HttpPost]  
    2.    [AllowAnonymous]  
    3.    [ValidateAntiForgeryToken]  
    4.    public async Task Register(RegisterViewModel model)  
    5.    {  
    6.        if (ModelState.IsValid)  
    7.        {  
    8.            var user = new ApplicationUser() { UserName = model.UserName };  
    9.            user.Email = model.Email;  
    10.            user.ConfirmedEmail = false;  
    11.            var result = await UserManager.CreateAsync(user, model.Password);  
    12.            if (result.Succeeded)  
    13.            {  
    14.                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(  
    15.                    new System.Net.Mail.MailAddress("[email protected]""Web Registration"),  
    16.                    new System.Net.Mail.MailAddress(user.Email));  
    17.                mail.Subject = "Email confirmation";  
    18.                mail.Body = string.Format("Dear {0}
      Thank you for your registration, please click on the below link to complete your registration: {1}"
      , user.UserName, Url.Action("ConfirmEmail""Account"new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));  
    19.                mail.IsBodyHtml = true;  
    20.   
    21.                 
    22.                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.outlook.com");  
    23.                smtp.UseDefaultCredentials = false;  
    24.                smtp.Credentials = new System.Net.NetworkCredential("[email protected]""password");  
    25.                smtp.EnableSsl = true;  
    26.    
    27.                smtp.Port = 587;  
    28.                smtp.Host = "smtp.outlook.com";  
    29.                smtp.Send(mail);  
    30.                return RedirectToAction("Confirm""Account"new { Email = user.Email });  
    31.            }  
    32.            else  
    33.            {  
    34.                AddErrors(result);  
    35.            }  
    36.        }  
    37.   
    38.        // If we got this far, something failed, redisplay form  478216  
    39.        return View(model);  
    40.    }  
     
    +1
  • Amit Gupta
    Hey
     
    Just be generaly aware that if you are using gmail smtp then you must allow less secure app in your gmail account 
     
    https://myaccount.google.com/lesssecureapps?pli=1
    and
    smtp.EnableSsl = true; 
    +1
  • Joginder Banger
    Please review your gmail setting.
     
    Ensure you set SmtpClient.Credentials after calling SmtpClient.UseDefaultCredentials = false.
     
    The order is important as setting SmtpClient.UseDefaultCredentials = false will reset SmtpClient.Credentials to null.
    +1
  • Vrushali Ghodke
    Hi Gcobani,
     
    have you checked this link or try all the solutions mentioned over here?
     
    https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not
     
    Please make sure you have entered the correct password and select the "Allow access" option when you got the mail to your account.
    0