Example #1
0
        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));
        }