// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Net.Mail;
using Umbraco.Cms.Core.Configuration.Models.Validation;
namespace Umbraco.Cms.Core.Configuration.Models;
///
/// Matches MailKit.Security.SecureSocketOptions and defined locally to avoid having to take
/// a dependency on this external library into Umbraco.Core.
///
///
public enum SecureSocketOptions
{
///
/// No SSL or TLS encryption should be used.
///
None = 0,
///
/// Allow the IMailService to decide which SSL or TLS options to use (default). If the server does not support SSL or
/// TLS, then the connection will continue without any encryption.
///
Auto = 1,
///
/// The connection should use SSL or TLS encryption immediately.
///
SslOnConnect = 2,
///
/// Elevates the connection to use TLS encryption immediately after reading the greeting and capabilities of the
/// server. If the server does not support the STARTTLS extension, then the connection will fail and a
/// NotSupportedException will be thrown.
///
StartTls = 3,
///
/// Elevates the connection to use TLS encryption immediately after reading the greeting and capabilities of the
/// server, but only if the server supports the STARTTLS extension.
///
StartTlsWhenAvailable = 4,
}
///
/// Typed configuration options for SMTP settings.
///
public class SmtpSettings : ValidatableEntryBase
{
internal const string StaticSecureSocketOptions = "Auto";
internal const string StaticDeliveryMethod = "Network";
///
/// Gets or sets a value for the SMTP from address to use for messages.
///
[Required]
[EmailAddress]
public string From { get; set; } = null!;
///
/// Gets or sets a value for the SMTP host.
///
public string? Host { get; set; }
///
/// Gets or sets a value for the SMTP port.
///
public int Port { get; set; }
///
/// Gets or sets a value for the secure socket options.
///
[DefaultValue(StaticSecureSocketOptions)]
public SecureSocketOptions SecureSocketOptions { get; set; } =
Enum.Parse(StaticSecureSocketOptions);
///
/// Gets or sets a value for the SMTP pick-up directory.
///
public string? PickupDirectoryLocation { get; set; }
///
/// Gets or sets a value for the SMTP delivery method.
///
[DefaultValue(StaticDeliveryMethod)]
public SmtpDeliveryMethod DeliveryMethod { get; set; } = Enum.Parse(StaticDeliveryMethod);
///
/// Gets or sets a value for the SMTP user name.
///
public string? Username { get; set; }
///
/// Gets or sets a value for the SMTP password.
///
public string? Password { get; set; }
}