Exemplo n.º 1
0
        private Task SendWithOptions(IdentityMessage message)
        {
            ThrowIf.IsArgumentNull(() => message);

            var builder = new MessageBuilder();

            builder.
            SetSubject(message.Subject).
            AddToRecipient(new Recipient {
                Email = message.Destination
            });

            //set the default from
            if (_options.DefaultFrom != null)
            {
                builder.SetFromAddress(_options.DefaultFrom);
            }

            //override replyTo if it was set by SendAsync
            if (_from != null)
            {
                builder.SetFromAddress(_from);
            }

            //do customization based on service options
            builder.SetClickTracking(_options.TrackingClicks);
            builder.SetDkim(_options.UseDkim);
            builder.SetOpenTracking(_options.TrackingOpen);
            builder.SetTestMode(_options.TestMode);

            //add body
            if (_options.UseHtmlBody)
            {
                builder.SetHtmlBody(message.Body);
            }
            else
            {
                builder.SetTextBody(message.Body);
            }

            //set the default replyTo
            if (_options.DefaultReplyTo != null)
            {
                builder.SetReplyToAddress(_options.DefaultReplyTo);
            }

            //override replyTo if it was set by SendAsync
            if (_replyTo != null)
            {
                builder.SetReplyToAddress(_replyTo);
            }

            //add tags and headers
            if (_options.DefaultHeaders != null && _options.DefaultHeaders.Count > 0)
            {
                foreach (var kvp in _options.DefaultHeaders)
                {
                    builder.AddCustomHeader(kvp.Key, kvp.Value);
                }
            }
            if (_options.DefaultTags != null && _options.DefaultTags.Count > 0)
            {
                _options.DefaultTags.ToList().ForEach(t => builder.AddTag(t));
            }

            //send the message
            return(_messageService.SendMessageAsync(_options.Domain, builder.GetMessage()));
        }