Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt 358 posts 841 karma points
    Jan 24, 2020 @ 14:25
    Matt
    0

    Error when submit contact form.

    Hi,

    When I submit my contact form on my server with Eukhost I get the following error;

    Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.

    This is the reply from my provider;

    As per the error we suggest to you please update the SMTP authentication on your mail script. Like email address and password details.

    After enabled the relay on your mail server you can able to sent mail from above script. But as per security concern we not recommended to enable replay on your server because it\'s change to start the spamming on server.

    Would anyone be able to take a look at my script and let me know how I can resolve this?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    using site.Models;
    using System.Net.Mail;
    
    namespace site.Controllers
    {
        public class ContactSurfaceController : SurfaceController
        {
            public const string PARTIAL_VIEW_FOLDER = "~/Views/Partials/";
            public ActionResult RenderForm()
            {
                return PartialView(PARTIAL_VIEW_FOLDER + "ContactForm.cshtml");
            }
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SubmitForm(ContactFormViewModel model)
            {
                if (ModelState.IsValid)
                {
                    SendEmail(model);
                    TempData["ContactSuccess"] = true;
                    return RedirectToCurrentUmbracoPage();
                }
                return CurrentUmbracoPage();
            }
    
            private void SendEmail(ContactFormViewModel model)
            {
                MailMessage message = new MailMessage(model.EmailAddress, "[email protected]");
                message.Subject = string.Format("Enquiry from {0} {1} - {2}", model.FirstName, model.LastName, model.Number);
                message.Body = model.Message;
                SmtpClient client = new SmtpClient("mail.sitedetails.org.uk", 25);
                client.Send(message);
            }
        }
    }
    

    Thanks in advance,

    Matt

  • Roger Jarl 22 posts 115 karma points
    Jan 28, 2020 @ 12:47
    Roger Jarl
    0

    Try this:

     private void SendEmail(ContactFormViewModel model)
        {
            MailMessage message = new MailMessage(model.EmailAddress, "[email protected]");
            message.Subject = string.Format("Enquiry from {0} {1} - {2}", model.FirstName, model.LastName, model.Number);
            message.Body = model.Message;
            SmtpClient client = new SmtpClient("mail.sitedetails.org.uk", 25);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("yourusername", "yourpassword");
            client.Send(message);
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft