Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem my request to register new users on my controller, does not work it throws an exception to connection failure. What could be the reason for this, the email domain is gmail not outlook account

What I have tried:

C#
<pre>   [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                user.Email = model.Email;
                user.ConfirmedEmail = false;
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
                        new System.Net.Mail.MailAddress("ggcobani@gmail.com", "Web Registration"),
                        new System.Net.Mail.MailAddress(user.Email));
                    m.Subject = "Email confirmation";
                    m.Body = string.Format("Dear {0}<BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>", user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));
                    m.IsBodyHtml = true;
                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mydomain.com");
                    smtp.Credentials = new System.Net.NetworkCredential("ggcobani@gmail.com", "password");
                    smtp.EnableSsl = true;
                    smtp.Send(m);
                    return RedirectToAction("Confirm", "Account", new { Email = user.Email });
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Posted
Comments
Richard MacCutchan 5-Feb-20 5:50am    
Which remote device are you trying to connect to? Whatever the reason for the error that is where you need to look.
gcogco10 5-Feb-20 5:51am    
Im connected to the University network, could this be the reason why fire wall blocks the request?
phil.o 5-Feb-20 6:01am    
Yes, it could. Most probably, the proxy would handle these cases.
F-ES Sitecore 5-Feb-20 5:58am    
The error is self-explanatory....the mail server is not responding in an appropriate manner. It could be because of a network issue between your web server and the smtp server, or it could be you are using the wrong settings, so wrong ssl setting, port, credentials etc. Double-check you are matching the requirements for the smtp server you are connecting to. At a guess I'd say you're at least sending the wrong credentials...the chances of "mydomain.com" using a gmail domain user to authenticate is next to zero.
gcogco10 5-Feb-20 7:28am    
@F-ES Sitecore i hear you mate, let me double check the settings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900