internal static SendGridConfiguration CreateConfiguration(JObject metadata) { SendGridConfiguration sendGridConfig = new SendGridConfiguration(); JObject configSection = (JObject)metadata.GetValue("sendGrid", StringComparison.OrdinalIgnoreCase); JToken value = null; if (configSection != null) { MailAddress mailAddress = null; if (configSection.TryGetValue("from", StringComparison.OrdinalIgnoreCase, out value) && SendGridHelpers.TryParseAddress((string)value, out mailAddress)) { sendGridConfig.FromAddress = mailAddress; } if (configSection.TryGetValue("to", StringComparison.OrdinalIgnoreCase, out value) && SendGridHelpers.TryParseAddress((string)value, out mailAddress)) { sendGridConfig.ToAddress = mailAddress; } } return(sendGridConfig); }
/// <inheritdoc/> public override void Initialize() { var sendGridConfig = SendGridHelpers.CreateConfiguration(Metadata); if (!string.IsNullOrEmpty(sendGridConfig.ApiKey)) { Config.UseSendGrid(sendGridConfig); } }
internal static void ApplyConfiguration(IConfiguration config, SendGridOptions options) { if (config == null) { return; } config.Bind(options); string to = config.GetValue <string>("to"); string from = config.GetValue <string>("from"); options.ToAddress = SendGridHelpers.Apply(options.ToAddress, to); options.FromAddress = SendGridHelpers.Apply(options.FromAddress, from); }
public Task AddAsync(SendGridMessage item, CancellationToken cancellationToken = default(CancellationToken)) { if (item == null) { throw new ArgumentNullException("item"); } SendGridHelpers.DefaultMessageProperties(item, _options, _attribute); if (!SendGridHelpers.IsToValid(item)) { throw new InvalidOperationException("A 'To' address must be specified for the message."); } if (item.From == null || string.IsNullOrEmpty(item.From.Email)) { throw new InvalidOperationException("A 'From' address must be specified for the message."); } _messages.Enqueue(item); return(Task.CompletedTask); }
public Task AddAsync(Mail item, CancellationToken cancellationToken = default(CancellationToken)) { if (item == null) { throw new ArgumentNullException("item"); } SendGridHelpers.DefaultMessageProperties(item, _config, _attribute); if (!SendGridHelpers.IsToValid(item)) { throw new InvalidOperationException("A 'To' address must be specified for the message."); } if (item.From == null || string.IsNullOrEmpty(item.From.Address)) { throw new InvalidOperationException("A 'From' address must be specified for the message."); } _messages.Add(item); return(Task.FromResult(0)); }
/// <inheritdoc/> public override void Initialize() { var sendGridConfig = SendGridHelpers.CreateConfiguration(Metadata); Config.UseSendGrid(sendGridConfig); }