예제 #1
0
        public async Task <GetSendQuotaResult> GetSendQuotaAsync(SesEmail message)
        {
            var request = new SesRequest("GetSendQuota");

            var text = await Send(request).ConfigureAwait(false);

            return(GetSendQuotaResponse.Parse(text).GetSendQuotaResult);
        }
예제 #2
0
        public static SesEmail FromMailMessage(MailMessage message)
        {
            #region Preconditions

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            #endregion

            var doc = new SesEmail
            {
                Source  = SesHelper.EncodeEmail(message.From),
                To      = message.To.Select(r => SesHelper.EncodeEmail(r)).ToArray(),
                Subject = new SesContent(message.Subject, CharsetType.UTF8)
            };

            // "Carbonmade" <*****@*****.**>
            if (message.ReplyTo != null)
            {
                doc.ReplyTo = new[] { SesHelper.EncodeEmail(message.ReplyTo) };
            }
            else if (message.ReplyToList.Count > 0)
            {
                doc.ReplyTo = message.ReplyToList.Select(r => SesHelper.EncodeEmail(r)).ToArray();
            }

            if (message.IsBodyHtml)
            {
                doc.Html = new SesContent(message.Body, CharsetType.UTF8);
            }
            else
            {
                doc.Html = new SesContent(message.Body, CharsetType.UTF8);
            }

            // Alternate view support
            if (message.AlternateViews != null)
            {
                foreach (var view in message.AlternateViews)
                {
                    using (var streamReader = new StreamReader(view.ContentStream))
                    {
                        var text = streamReader.ReadToEnd();

                        switch (view.ContentType.MediaType)
                        {
                        case "text/plain": doc.Text = new SesContent(text, CharsetType.UTF8); break;

                        case "text/html": doc.Html = new SesContent(text, CharsetType.UTF8); break;
                        }
                    }
                }
            }

            return(doc);
        }
예제 #3
0
        public async Task <SendEmailResult> SendEmailAsync(SesEmail message)
        {
            var request = new SesRequest("SendEmail");

            foreach (var pair in message.ToParams())
            {
                request.Add(pair.Key, pair.Value);
            }

            var text = await SendWithRetryPolicy(request, retryPolicy).ConfigureAwait(false);

            return(SendEmailResponse.Parse(text).SendEmailResult);
        }
예제 #4
0
        public static SesEmail FromMailMessage(MailMessage message)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var doc = new SesEmail
            {
                Source  = SesHelper.EncodeMailAddress(message.From),
                To      = message.To.Select(r => SesHelper.EncodeMailAddress(r)).ToArray(),
                Subject = new SesContent(message.Subject, CharsetType.UTF8)
            };

            // "Carbonmade" <*****@*****.**>


            if (message.ReplyToList.Count > 0)
            {
                doc.ReplyTo = EncodeMailAddressCollection(message.ReplyToList);
            }
#pragma warning disable CS0618 // Type or member is obsolete
            else if (message.ReplyTo != null)
            {
                doc.ReplyTo = new[] { SesHelper.EncodeMailAddress(message.ReplyTo) };
            }
#pragma warning restore CS0618


            if (message.IsBodyHtml)
            {
                doc.Html = new SesContent(message.Body, CharsetType.UTF8);
            }
            else
            {
                doc.Text = new SesContent(message.Body, CharsetType.UTF8);
            }


            if (message.CC.Count > 0)
            {
                doc.CC = EncodeMailAddressCollection(message.CC);
            }

            // Alternate view support
            if (message.AlternateViews != null)
            {
                foreach (var view in message.AlternateViews)
                {
                    using var streamReader = new StreamReader(view.ContentStream);

                    string text = streamReader.ReadToEnd();

                    switch (view.ContentType.MediaType)
                    {
                    case "text/plain": doc.Text = new SesContent(text, CharsetType.UTF8); break;

                    case "text/html": doc.Html = new SesContent(text, CharsetType.UTF8); break;
                    }
                }
            }

            return(doc);
        }
예제 #5
0
 public Task <SendEmailResult> SendEmailAsync(MailMessage message)
 => SendEmailAsync(SesEmail.FromMailMessage(message));