0

I'm current trying to get this to work following this tutorial:

http://www.codeproject.com/Tips/738090/ASP-NET-MVC-Confirm-Registration-Email

But I'm having an issue connecting to my smtp server. I own a .dk domain via www.one.com and I'm trying to test this functionality with their SMTP server using my own e-mail logon credentials (which are 100% correct, also in the code).

Currently My register method looks like this:

 [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.ConfirmEmail = false;
      var result = await UserManager.CreateAsync(user, model.Password);
      if (result.Succeeded)
       {
           var m = new MailMessage(new MailAddress("gwiz@blackweb.dk", "Web Registration"), new 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;

        //smtp.Credentials = new NetworkCredential("gwiz@blackweb.dk", "Tengri8971");
        //smtp.EnableSsl = true;    
           var smtp = new SmtpClient();
           smtp.Host = "send.one.com";
           smtp.EnableSsl = true;
           var networkCredential = new NetworkCredential("thecorrectusername", "thecorrectpassword");
           smtp.UseDefaultCredentials = false;
           smtp.Credentials = networkCredential;
           smtp.Port = 465;
           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);
}

But whenever I try to create a new user I get the following exception (as far as I can find out online it means it's not properly connecting with the SMTP server?).

Serverfejl i programmet '/'.
Der kunne ikke læses data fra transportforbindelsen: net_io_connectionclosed.
Beskrivelse: Der opstod en undtagelse, der ikke blev behandlet, under udførelse af den aktuelle webanmodning. Se staksporingen for at få flere oplysninger om fejlen, og hvor den kom fra i koden.

Detaljer om undtagelse: System.IO.IOException: Der kunne ikke læses data fra transportforbindelsen: net_io_connectionclosed.

Kildefejl:


Linje 404:           smtp.Credentials = networkCredential;
Linje 405:           smtp.Port = 465;
Linje 406:           smtp.Send(m);
Linje 407:        return RedirectToAction("Confirm", "Account", new { Email = user.Email });
Linje 408:      }


Kildefil: c:\Users\Giuseppe\Desktop\MEV3\MEV3\Controllers\AccountController.cs    Linje: 406

Staksporing:


[IOException: Der kunne ikke læses data fra transportforbindelsen: net_io_connectionclosed.]
   System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) +1498507
   System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +227
   System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +16
   System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +674
   System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
   System.Net.Mail.SmtpClient.GetConnection() +44
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1554

[SmtpException: Der opstod en fejl ved afsendelsen af e-mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1906
   MEV3.Controllers.<Register>d__20.MoveNext() in c:\Users\Giuseppe\Desktop\MEV3\MEV3\Controllers\AccountController.cs:406
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
   lambda_method(Closure , Task ) +64
   System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +64
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114
   System.Web.Mvc.Async.<>c__DisplayClass34.<BeginInvokeAsynchronousActionMethod>b__33(IAsyncResult asyncResult) +65
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +135
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c() +117
   System.Web.Mvc.Async.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e() +323
   System.Web.Mvc.Async.<>c__DisplayClass30.<BeginInvokeActionMethodWithFilters>b__2f(IAsyncResult asyncResult) +44
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +135
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
   System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +72
   System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +132
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129


Versionsoplysninger: Microsoft .NET Framework version:4.0.30319; ASP.NET version:4.0.30319.34212 

As far as I can tell my port, smtp address, logon credentials etc. are all correct but it still doesn't work? I would appreciate any input you might have that could help me sort it out.

ObedMarsh
  • 433
  • 4
  • 19
  • Can you translate the error to English, or otherwise get an English version of the exception by changing your application's culture? This site is English. – mason Mar 11 '15 at 00:01
  • Whether "from mail address" is real one and already created in mail server? – Peyman Mar 11 '15 at 00:02
  • There's no need to translate the error the entire stacktrace is english? It's a basic "System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed." exception. And yes the e-mail is working and exists on the server I've used it several times and confirmed the login credentials hundreds of times. – ObedMarsh Mar 11 '15 at 13:52

1 Answers1

0

This question solved my problem completely, I simply had to change my port from 465 to 587. The why is explained in the below thread.

SmtpException: Unable to read data from the transport connection: net_io_connectionclosed

Community
  • 1
  • 1
ObedMarsh
  • 433
  • 4
  • 19