Copied to clipboard

Flag this post as spam?

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


  • bh 408 posts 1395 karma points
    Jun 20, 2022 @ 18:04
    bh
    0

    The SMTP host was not specified.

    I'm getting the 500 error:

    The SMTP host was not specified.

    But, I've specified the SMTP in appsettings.json

    "Global": {
            "Id": "redacted",
            "Smtp": {
              "From": "[email protected]",
              "DeliveryMethod": "SpecifiedPickupDirectory",
              "PickupDirectoryLocation": "\\\\pathtomy\pickupdir"
            },
            "Timeout": "01:00:00"
          }
    

    To double down I also added it to web.config:

    <system.net>
          <mailSettings>
            <smtp deliveryMethod="SpecifiedPickupDirectory">
              <specifiedPickupDirectory pickupDirectoryLocation="\\pathtomy\pickupdir" />
            </smtp>
          </mailSettings>
        </system.net>
    

    What am I missing?

  • Ambert van Unen 175 posts 817 karma points c-trib
    Jun 20, 2022 @ 19:12
    Ambert van Unen
    0

    Exactly what is in the error :-)

    Smtp requires a "Host"

    "Global": {
        "Id": "redacted",
        "Smtp": {
          "From": "[email protected]",
          "Host": "localhost",
          "DeliveryMethod": "SpecifiedPickupDirectory",
          "PickupDirectoryLocation": "\\\\pathtomy\pickupdir"
        },
        "Timeout": "01:00:00"
      }
    
  • bh 408 posts 1395 karma points
    Jun 20, 2022 @ 19:50
    bh
    0

    @AmbertvanUnen

    Thanks for your response! The full error:

    System.InvalidOperationException: The SMTP host was not specified.\r\n at System.Net.Mail.SmtpClient.CheckHostAndPort()\r\n

    I got the same error after adding "Host": "localhost", to appsettings.json.

  • Ambert van Unen 175 posts 817 karma points c-trib
    Jun 21, 2022 @ 06:20
    Ambert van Unen
    0

    Do you get this error on startup or when sending a form? Do you have some custom implementation?

  • bh 408 posts 1395 karma points
    Jun 21, 2022 @ 12:32
    bh
    0

    @AmbertvanUnen the error only fires when attempting to send a MailMessage

    using (MailMessage objMail = new MailMessage()){ 
                    foreach(string recipient in RecipientsList) { 
                        objMail.To.Add(new MailAddress(recipient));
                    }
                    objMail.Subject = strDomain + " | Contact Form Submission";
                    objMail.Body = strLeadInfo;
                    objMail.IsBodyHtml = true;
    
                    using (SmtpClient objSmtp = new SmtpClient()){ 
                        objSmtp.Send(objMail);
                    }
                }
    
    "Global": {
            "Id": "redacted",
            "Smtp": {
              "From": "[email protected]",
              "Host": "localhost",
              "DeliveryMethod": "SpecifiedPickupDirectory",
              "PickupDirectoryLocation": "\\\\pathtomy\\pickupdir"
            },
    
  • Johan Runsten 38 posts 276 karma points c-trib
    Jun 22, 2022 @ 06:54
    Johan Runsten
    0

    Hi!

    I believe the Umbraco smtp settings are specific to Umbraco i.e. Forms and password resets.

    If you're using the native .NET way to send emails yourself you have to also configure your native smtp settings, as you've done, but with the host information as well.

    Have a look at https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/smtp-element-network-settings.

    You can also set the configuration on the SmtpClient itself, if you want to read your Umbraco config settings.

  • bh 408 posts 1395 karma points
    Jun 22, 2022 @ 17:49
    bh
    0

    Thanks @JohanRunsten

    That makes sense what you said about the appsettings.json smtp configuration applying to Umbraco mail delivery. I hadn't thought of that.

    As you see in my original post, I also added the smtp configuration to the web.config file in my root.

  • Johan Runsten 38 posts 276 karma points c-trib
    Jun 22, 2022 @ 19:17
    Johan Runsten
    0

    Hi!

    But you didn't add the host setting right? Check out the example configuration at the bottom of this page: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/smtp-element-network-settings

  • bh 408 posts 1395 karma points
    Jun 27, 2022 @ 15:44
    bh
    1

    So I have this in the web.config in the root of my Umbraco 9 site.

    <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="\\pathtomy\dir" />          
          </smtp>
    

    And I get the The SMTP host was not specified error.

    I have the same configuration in my Umbraco 8 site and it sends without error.

    I hardcoded the pickup directory in my Umbraco 9 site and now it sends without error.

    using (SmtpClient objSmtp = new SmtpClient()){ 
                        objSmtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                        objSmtp.PickupDirectoryLocation = @"\\pathtomy\dir";
                        objSmtp.Send(objMail);
                    }
    

    It's as if .Net Core doesn't honor the SMTP web.config configuration.

    Here's a related thread I found on the subject: https://github.com/umbraco/Umbraco-CMS/pull/11548

Please Sign in or register to post replies

Write your reply to:

Draft