so im trying to build a email form but I keep getting this error: "The connection attempt failed because the connected computer did not respond within a certain time or because of the established connection to the host computer no longer works 194.9.94.72:25"

Here's some code:

Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Wideart.Models
{
    public class SendMail
    {
        public string Name { get; set; }
        public string Email { get; set; }
        public string Number { get; set; }
        public string Message { get; set; }
    }
}

View:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="wrapper" class="boxed">
    <img src="/images/heard2.jpg" />
    <div class="body-wrapper">
        <div class="container">
            <div class="row">
                <div class="col-md-8 col-sm-8">
                    <div class="contact-body">
                        <h3 class="h3-body-title">
                            Leave A Message
                        </h3>
                        @if ( ViewData [ "Message" ] != null )
                        {
                            <div class="alert alert-success">Your e-mail has been sent.</div>
                        }
                        <form class="form-wrapper" id="contact-form" method="post" role="form" novalidate>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-xs-7">
                                        <label for="name">
                                            Name *
                                        </label>
                                        <input type="text" id="name" name="name" class="form-control" data-errmsg="Name is required."
                                               placeholder="Your Name" required />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-xs-7">
                                        <label for="email">
                                            Email *
                                        </label>
                                        <input type="text" id="email" name="email" class="form-control" data-errmsg="Email is required."
                                               placeholder="Your Email" required />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-xs-7">
                                        <label for="number">
                                            Number
                                        </label>
                                        <input type="text" id="number" name="number" class="form-control"
                                               placeholder="Your Number" />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-xs-8">
                                        <label for="message">
                                            Message *
                                        </label>
                                        <textarea id="message" name="message" class="form-control" data-errmsg="Message is required."
                                                  placeholder="Your Message" rows="3" required></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-2 col-sm-2 offset2">
                                    <input type="submit" id="sendMail" value="Send" class="btn btn-lg" />
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3 col-md-offset-1 col-sm-offset-1">
                    <div class="sidebar">
                        <div class="sidebar-block">
                            <h3 class="h3-sidebar-title">
                                Contact Me
                            </h3>
                            <div class="sidebar-icon-item">
                                <i class="icon-home"></i>Stockholm, Sweden
                            </div>
                        </div>
                        <div class="col-md-6 col-sm-6">
                            <div class="team-member">
                                <img alt="" id="sebbe" src="/images/Sebastian Wideroos.jpg" class="thumbnail" />
                                <h3 class="team-member-name h3-body-title">
                                    Sebastian Wideroos
                                </h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

Controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Mail;
using Wideart.Models;

namespace Wideart.Controllers
{
    public class ContactController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(SendMail input)
        {
            var mail = new MailMessage("no-reply@wideart.se", "info@wideart.se");
            var client = new SmtpClient();
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Host = "mailcluster.loopia.se";
            mail.Body = input.Name + "" + input.Email + "" + input.Number + "" + input.Message;
            client.Send(mail);

            ViewData ["Message"] = mail;

            return View(mail);
        }
    }
}

JavaScript:

$("#sendMail").on("click", function (e) {

});

Web Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network port="25"/>
      </smtp>
    </mailSettings>
  </system.net>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

The SMTP server and port is: mailcluster.loopia.se | 25

Please help!

Related posts

Recent Viewed