private NoticeSendResult SendMessage(NotifyMessage m) { //Check if we need to query stats RefreshQuotaIfNeeded(); if (quota != null) { lock (locker) { if (quota.Max24HourSend <= quota.SentLast24Hours) { //Quota exceeded, queue next refresh to +24 hours lastRefresh = DateTime.UtcNow.AddHours(24); log.WarnFormat("Quota limit reached. setting next check to: {0}", lastRefresh); return NoticeSendResult.SendingImpossible; } } } var dest = new Destination { ToAddresses = m.To.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(a => MailAddressUtils.Create(a).Address).ToList(), }; var subject = new Content(MimeHeaderUtils.EncodeMime(m.Subject)) { Charset = Encoding.UTF8.WebName, }; Body body; if (m.ContentType == Pattern.HTMLContentType) { body = new Body(new Content(HtmlUtil.GetText(m.Content)) { Charset = Encoding.UTF8.WebName }); body.Html = new Content(GetHtmlView(m.Content)) { Charset = Encoding.UTF8.WebName }; } else { body = new Body(new Content(m.Content) { Charset = Encoding.UTF8.WebName }); } var from = MailAddressUtils.Create(m.From).ToEncodedString(); var request = new SendEmailRequest {Source = from, Destination = dest, Message = new Message(subject, body)}; if (!string.IsNullOrEmpty(m.ReplyTo)) { request.ReplyToAddresses.Add(MailAddressUtils.Create(m.ReplyTo).Address); } ThrottleIfNeeded(); var response = ses.SendEmail(request); lastSend = DateTime.UtcNow; return response != null ? NoticeSendResult.OK : NoticeSendResult.TryOnceAgain; }
public void Encode() { Assert.AreEqual("=?utf-8?B?0YrRitGK?=", MimeHeaderUtils.EncodeMime("ъъъ")); Assert.AreEqual("ddd", MimeHeaderUtils.EncodeMime("ddd")); }