Copied to clipboard

Flag this post as spam?

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


  • bh 336 posts 1135 karma points
    4 days ago
    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 158 posts 766 karma points c-trib
    4 days ago
    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 336 posts 1135 karma points
    4 days ago
    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 158 posts 766 karma points c-trib
    4 days ago
    Ambert van Unen
    0

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

  • bh 336 posts 1135 karma points
    4 days ago
    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 12 posts 123 karma points c-trib
    3 days ago
    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 336 posts 1135 karma points
    2 days ago
    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 12 posts 123 karma points c-trib
    2 days ago
    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

Please Sign in or register to post replies

Write your reply to:

Draft