Example #1
0
        /// <summary>
        /// Send an email to a single recipient
        /// </summary>
        /// <param name="to">To.</param>
        /// <param name="from">From.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="htmlContent">Content of the HTML.</param>
        /// <param name="textContent">Content of the text.</param>
        /// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
        /// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
        /// <param name="subscriptionTracking">The subscription tracking.</param>
        /// <param name="replyTo">The reply to.</param>
        /// <param name="attachments">The attachments.</param>
        /// <param name="templateId">The template identifier.</param>
        /// <param name="sections">The sections.</param>
        /// <param name="headers">The headers.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="customArgs">The custom arguments.</param>
        /// <param name="sendAt">The send at.</param>
        /// <param name="batchId">The batch identifier.</param>
        /// <param name="unsubscribeOptions">The unsubscribe options.</param>
        /// <param name="ipPoolName">Name of the ip pool.</param>
        /// <param name="mailSettings">The mail settings.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The message id.
        /// </returns>
        /// <remarks>
        /// This is a convenience method with simplified parameters.
        /// If you need more options, use the <see cref="SendAsync" /> method.
        /// </remarks>
        /// <exception cref="Exception">Email exceeds the size limit</exception>
        public Task <string> SendToSingleRecipientAsync(
            MailAddress to,
            MailAddress from,
            string subject,
            string htmlContent,
            string textContent,
            bool trackOpens  = true,
            bool trackClicks = true,
            SubscriptionTrackingSettings subscriptionTracking = null,
            MailAddress replyTo = null,
            IEnumerable <Attachment> attachments = null,
            string templateId = null,
            IEnumerable <KeyValuePair <string, string> > sections = null,
            IEnumerable <KeyValuePair <string, string> > headers  = null,
            IEnumerable <string> categories = null,
            IEnumerable <KeyValuePair <string, string> > customArgs = null,
            DateTime?sendAt = null,
            string batchId  = null,
            UnsubscribeOptions unsubscribeOptions = null,
            string ipPoolName                   = null,
            MailSettings mailSettings           = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var recipients = new[] { to };

            return(SendToMultipleRecipientsAsync(recipients, from, subject, htmlContent, textContent, trackOpens, trackClicks, subscriptionTracking, replyTo, attachments, templateId, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, cancellationToken));
        }
Example #2
0
        /// <summary>
        /// Send an email to a single recipient using a dynamic template.
        /// </summary>
        /// <param name="to">To.</param>
        /// <param name="from">From.</param>
        /// <param name="dynamicTemplateId">The identifier of the template.</param>
        /// <param name="dynamicData">The data to be merged in the content.</param>
        /// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
        /// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
        /// <param name="subscriptionTracking">The subscription tracking.</param>
        /// <param name="replyTo">The reply to.</param>
        /// <param name="attachments">The attachments.</param>
        /// <param name="sections">The sections.</param>
        /// <param name="headers">The headers.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="customArgs">The custom arguments.</param>
        /// <param name="sendAt">The send at.</param>
        /// <param name="batchId">The batch identifier.</param>
        /// <param name="unsubscribeOptions">The unsubscribe options.</param>
        /// <param name="mailSettings">The mail settings.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The result.
        /// </returns>
        /// <remarks>
        /// This is a convenience method with simplified parameters.
        /// If you need more options, use the <see cref="SendAsync" /> method.
        /// </remarks>
        /// <exception cref="ArgumentOutOfRangeException">Too many recipients.</exception>
        /// <exception cref="Exception">Email exceeds the size limit.</exception>
        public Task <WarmupResult> SendToSingleRecipientAsync(
            MailAddress to,
            MailAddress from,
            string dynamicTemplateId,
            object dynamicData = null,
            bool trackOpens    = true,
            bool trackClicks   = true,
            SubscriptionTrackingSettings subscriptionTracking = null,
            MailAddress replyTo = null,
            IEnumerable <Attachment> attachments = null,
            IEnumerable <KeyValuePair <string, string> > sections = null,
            IEnumerable <KeyValuePair <string, string> > headers  = null,
            IEnumerable <string> categories = null,
            IEnumerable <KeyValuePair <string, string> > customArgs = null,
            DateTime?sendAt = null,
            string batchId  = null,
            UnsubscribeOptions unsubscribeOptions = null,
            MailSettings mailSettings             = null,
            MailPriority priority = MailPriority.Normal,
            CancellationToken cancellationToken = default)
        {
            var recipients = new[] { to };

            return(SendToMultipleRecipientsAsync(recipients, from, dynamicTemplateId, dynamicData, trackOpens, trackClicks, subscriptionTracking, replyTo, attachments, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, mailSettings, priority, cancellationToken));
        }
Example #3
0
        /// <summary>
        /// Send the same email to multiple recipients without using a template (which means you must provide the subject, html content and text content).
        /// </summary>
        /// <param name="recipients">The recipients.</param>
        /// <param name="from">From.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="htmlContent">Content of the HTML.</param>
        /// <param name="textContent">Content of the text.</param>
        /// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
        /// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
        /// <param name="subscriptionTracking">The subscription tracking.</param>
        /// <param name="replyTo">The reply to.</param>
        /// <param name="attachments">The attachments.</param>
        /// <param name="sections">The sections.</param>
        /// <param name="headers">The headers.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="customArgs">The custom arguments.</param>
        /// <param name="sendAt">The send at.</param>
        /// <param name="batchId">The batch identifier.</param>
        /// <param name="unsubscribeOptions">The unsubscribe options.</param>
        /// <param name="ipPoolName">Name of the ip pool.</param>
        /// <param name="mailSettings">The mail settings.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The message id.
        /// </returns>
        /// <remarks>
        /// This is a convenience method with simplified parameters.
        /// If you need more options, use the <see cref="SendAsync" /> method.
        /// </remarks>
        /// <exception cref="ArgumentOutOfRangeException">Too many recipients.</exception>
        /// <exception cref="Exception">Email exceeds the size limit.</exception>
        public Task <string> SendToMultipleRecipientsAsync(
            IEnumerable <MailAddress> recipients,
            MailAddress from,
            string subject,
            string htmlContent,
            string textContent,
            bool trackOpens  = true,
            bool trackClicks = true,
            SubscriptionTrackingSettings subscriptionTracking = null,
            MailAddress replyTo = null,
            IEnumerable <Attachment> attachments = null,
            IEnumerable <KeyValuePair <string, string> > sections = null,
            IEnumerable <KeyValuePair <string, string> > headers  = null,
            IEnumerable <string> categories = null,
            IEnumerable <KeyValuePair <string, string> > customArgs = null,
            DateTime?sendAt = null,
            string batchId  = null,
            UnsubscribeOptions unsubscribeOptions = null,
            string ipPoolName                   = null,
            MailSettings mailSettings           = null,
            MailPriority priority               = MailPriority.Normal,
            CancellationToken cancellationToken = default)
        {
            var personalizations = new[]
            {
                new MailPersonalization
                {
                    To = recipients.ToArray()
                }
            };

            var contents = new List <MailContent>();

            if (!string.IsNullOrEmpty(textContent))
            {
                contents.Add(new MailContent("text/plain", textContent));
            }
            if (!string.IsNullOrEmpty(htmlContent))
            {
                contents.Add(new MailContent("text/html", htmlContent));
            }

            var trackingSettings = new TrackingSettings
            {
                ClickTracking = new ClickTrackingSettings
                {
                    EnabledInHtmlContent = trackClicks,
                    EnabledInTextContent = trackClicks
                },
                OpenTracking = new OpenTrackingSettings {
                    Enabled = trackOpens
                },
                GoogleAnalytics = new GoogleAnalyticsSettings {
                    Enabled = false
                },
                SubscriptionTracking = subscriptionTracking
            };

            return(SendAsync(personalizations, subject, contents, from, replyTo, attachments, null, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, trackingSettings, priority, cancellationToken));
        }
Example #4
0
        /// <summary>
        /// Send the same email to multiple recipients.
        /// </summary>
        /// <param name="recipients">The recipients.</param>
        /// <param name="from">From.</param>
        /// <param name="dynamicTemplateId">The identifier of the template.</param>
        /// <param name="dynamicData">The data to be merged in the content.</param>
        /// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
        /// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
        /// <param name="subscriptionTracking">The subscription tracking.</param>
        /// <param name="replyTo">The reply to.</param>
        /// <param name="attachments">The attachments.</param>
        /// <param name="sections">The sections.</param>
        /// <param name="headers">The headers.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="customArgs">The custom arguments.</param>
        /// <param name="sendAt">The send at.</param>
        /// <param name="batchId">The batch identifier.</param>
        /// <param name="unsubscribeOptions">The unsubscribe options.</param>
        /// <param name="ipPoolName">Name of the ip pool.</param>
        /// <param name="mailSettings">The mail settings.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The message id.
        /// </returns>
        /// <remarks>
        /// This is a convenience method with simplified parameters.
        /// If you need more options, use the <see cref="SendAsync" /> method.
        /// </remarks>
        /// <exception cref="ArgumentOutOfRangeException">Too many recipients.</exception>
        /// <exception cref="Exception">Email exceeds the size limit.</exception>
        public Task <string> SendToMultipleRecipientsAsync(
            IEnumerable <MailAddress> recipients,
            MailAddress from,
            string dynamicTemplateId,
            object dynamicData = null,
            bool trackOpens    = true,
            bool trackClicks   = true,
            SubscriptionTrackingSettings subscriptionTracking = null,
            MailAddress replyTo = null,
            IEnumerable <Attachment> attachments = null,
            IEnumerable <KeyValuePair <string, string> > sections = null,
            IEnumerable <KeyValuePair <string, string> > headers  = null,
            IEnumerable <string> categories = null,
            IEnumerable <KeyValuePair <string, string> > customArgs = null,
            DateTime?sendAt = null,
            string batchId  = null,
            UnsubscribeOptions unsubscribeOptions = null,
            string ipPoolName                   = null,
            MailSettings mailSettings           = null,
            MailPriority priority               = MailPriority.Normal,
            CancellationToken cancellationToken = default)
        {
            if (!Template.IsDynamic(dynamicTemplateId))
            {
                throw new ArgumentException($"{dynamicTemplateId} is not a valid dynamic template identifier.", nameof(dynamicTemplateId));
            }

            var personalizations = new[]
            {
                new MailPersonalization
                {
                    To          = recipients.ToArray(),
                    DynamicData = dynamicData
                }
            };

            var trackingSettings = new TrackingSettings
            {
                ClickTracking = new ClickTrackingSettings
                {
                    EnabledInHtmlContent = trackClicks,
                    EnabledInTextContent = trackClicks
                },
                OpenTracking = new OpenTrackingSettings {
                    Enabled = trackOpens
                },
                GoogleAnalytics = new GoogleAnalyticsSettings {
                    Enabled = false
                },
                SubscriptionTracking = subscriptionTracking
            };

            return(SendAsync(personalizations, null, null, from, replyTo, attachments, dynamicTemplateId, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, trackingSettings, priority, cancellationToken));
        }
Example #5
0
        /// <summary>
        /// Send the same email to multiple recipients
        /// </summary>
        /// <remarks>
        /// This is a convenience method with simplified parameters.
        /// If you need more options, use the <see cref="SendAsync"/> method.
        /// </remarks>
        public Task SendToMultipleRecipientsAsync(
            IEnumerable <MailAddress> recipients,
            MailAddress from,
            string subject,
            string htmlContent,
            string textContent,
            bool trackOpens  = true,
            bool trackClicks = true,
            SubscriptionTrackingSettings subscriptionTracking = null,
            MailAddress replyTo = null,
            IEnumerable <Attachment> attachments = null,
            string templateId = null,
            IEnumerable <KeyValuePair <string, string> > sections = null,
            IEnumerable <KeyValuePair <string, string> > headers  = null,
            IEnumerable <string> categories = null,
            DateTime?sendAt = null,
            string batchId  = null,
            UnsubscribeOptions unsubscribeOptions = null,
            string ipPoolName                   = null,
            MailSettings mailSettings           = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var personalizations = recipients.Select(r => new MailPersonalization {
                To = new[] { r }
            });
            var contents = new[]
            {
                new MailContent("text/plain", textContent),
                new MailContent("text/html", htmlContent)
            };
            var trackingSettings = new TrackingSettings
            {
                ClickTracking = new ClickTrackingSettings
                {
                    Enabled = trackClicks,
                    EnabledInTextContent = trackClicks
                },
                OpenTracking = new OpenTrackingSettings {
                    Enabled = trackOpens
                },
                GoogleAnalytics = new GoogleAnalyticsSettings {
                    Enabled = false
                },
                SubscriptionTracking = subscriptionTracking
            };

            return(SendAsync(personalizations, subject, contents, from, replyTo, attachments, templateId, sections, headers, categories, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, trackingSettings, cancellationToken));
        }