Exemplo n.º 1
0
        void ReportFailure(string text, ImmutableEnvelope envelope)
        {
            // we do not report failure on attempts to send mail messages
            // this could be a loop
            // we can't report them anyway (since mail sending is not available)
            // note, that this could be an indirect loop.
            if (text.Contains(typeof(SendMailMessage).Name))
            {
                return;
            }

            if (text.Contains(typeof(MessageQuarantined).Name))
            {
                return;
            }

            var name = envelope.Message.GetType().Name.Replace("Command", "");

            var subject = string.Format("[Error]: S2 fails '{0}'", name);


            var builder = new StringBuilder();

            builder.AppendFormat(
                @"<p>Support,</p><p>Something just went horribly wrong - there is a problem that I can't resolve. Please check the error log <strong>ASAP</strong>.</p>
                        <p>Here are a few details to help you out:</p><pre>");

            builder.AppendLine(WebUtility.HtmlEncode(text));

            builder.AppendFormat("</pre><p>You can use S2 Maintenance to get the error details.</p><p>Sincerely,<br /> Hub AI</p>");



            // if we don't fit in the limits
            if (text.Length >= 1024 * 1024)
            {
                const string body    = "Subj, please notify Lokad support team immediately";
                const string subj    = "[S2]: Quarantine overflow";
                var          message = new SendMailMessage(new[] { new Email("*****@*****.**") }, subj,
                                                           body, false, null, null, null);
                _writer.SendCommand(message, true);
                // fail immediately

                return;
            }

            var to = new[]
            {
                new Email("*****@*****.**", "Salescast Support"),
                new Email("*****@*****.**", "Rinat Abdullin")
            };
            var cmd = new SendMailMessage(to, subject, builder.ToString(), true, null, null, null);

            _writer.SendCommand(cmd, true);
            var buffer = _streamer.SaveEnvelopeData(envelope);
            var names  = new[] { ContractEvil.GetContractReference(envelope.Message.GetType()) };

            _writer.Publish(new MessageQuarantined(text, buffer, names, DateTime.UtcNow));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Отправить сообщение
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public Task <BaseApiResponse> SendEmail(SendMailMessage message)
        {
            var toMes = ToMailMessage(message);

            GetRepository <MailMessageInteraction>().CreateHandled(toMes.Item1);
            GetRepository <InteractionStatusLog>().CreateHandled(toMes.Item2);
            GetRepository <InteractionAttachment>().CreateHandled(toMes.Item3);

            return(TrySaveChangesAndReturnResultAsync("Email-сообщение добавлено в очередь"));
        }
Exemplo n.º 3
0
 public void sendEmail(int type)
 {
     using (SqlTransaction trans = SQLHelp.BeginTransaction())
     {
         try
         {
             string    sql = "select * from System_Message where isSend=" + (int)isSend.未发送 + " and IsDelete!=" + (int)SysStatus.除 + " and [Type]=" + type + " and Timing=" + (int)MessageTiming.定时发送;
             DataTable dt  = SQLHelp.ExecuteDataTable(sql, CommandType.Text);
             string    ids = "";
             if (dt != null && dt.Rows.Count > 0)
             {
                 foreach (DataRow row in dt.Rows)
                 {
                     DateTime pushDate = Convert.ToDateTime(row["CreateTime"]);
                     DateTime curDate  = DateTime.Now;
                     TimeSpan ts       = pushDate - curDate;
                     if (ts.Minutes <= 2)
                     {
                         ids += row["Id"].ToString() + ",";
                     }
                     if (!string.IsNullOrWhiteSpace(ids) && ids.Length > 0)
                     {
                         ids = ids.Substring(0, ids.Length - 1);
                         string upSql  = "update System_Message set isSend=" + (int)isSend.已发送 + " where Id in (" + ids + ")";
                         int    number = SQLHelp.ExecuteNonQuery(upSql, CommandType.Text);
                         trans.Commit();
                     }
                 }
                 foreach (DataRow row in dt.Rows)
                 {
                     string Subject = string.IsNullOrWhiteSpace(Convert.ToString(row["Title"])) ? "无题" : row["Title"].ToString();
                     string Body    = string.IsNullOrWhiteSpace(Convert.ToString(row["Contents"])) ? "无内容" : row["Contents"].ToString();
                     if (!string.IsNullOrWhiteSpace(Convert.ToString(row["ReceiverEmail"])))
                     {
                         string href = "";
                         if (!string.IsNullOrWhiteSpace(Convert.ToString(row["CreatorName"])))
                         {
                             Body += "<br/><h4>发件人:" + row["CreatorName"].ToString() + "</h4>";
                         }
                         if (!string.IsNullOrWhiteSpace(Convert.ToString(row["Href"])))
                         {
                             href = "<br/><h3><a href=" + row["Href"].ToString() + ">点击此处可查看详细信息</a></h3>";
                         }
                         SendMailMessage.SendMessage(Subject, Body + href, row["ReceiverEmail"].ToString());
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             _logger.Info("EmailPost:" + ex.Message);
             trans.Rollback();
         }
     }
 }
Exemplo n.º 4
0
 private async Task HandleMailMessageAsync(SendMailMessage message)
 {
     try
     {
         await _mailSender.SendEmailAsync(message);
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "Error while sending message");
     }
 }
Exemplo n.º 5
0
 static public int get_mailTitle(IntPtr l)
 {
     try {
         SendMailMessage self = (SendMailMessage)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.mailTitle);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 6
0
 static public int get_receiverAddress(IntPtr l)
 {
     try {
         SendMailMessage self = (SendMailMessage)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.receiverAddress);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 7
0
 static public int constructor(IntPtr l)
 {
     try {
         SendMailMessage o;
         o = new SendMailMessage();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 8
0
 static public int set_mailTitle(IntPtr l)
 {
     try {
         SendMailMessage self = (SendMailMessage)checkSelf(l);
         System.String   v;
         checkType(l, 2, out v);
         self.mailTitle = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 9
0
 static public int set_senderId(IntPtr l)
 {
     try {
         SendMailMessage self = (SendMailMessage)checkSelf(l);
         System.UInt64   v;
         checkType(l, 2, out v);
         self.senderId = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 10
0
        private void SendEmailToAdmin(string fullErrorMessage)
        {
            var emailToText = ConfigurationManager.AppSettings["EmailAlertSystemError"];
            var emailTo     = emailToText.Split(',').ToList();

            List <MailProfile> mailTo = new List <MailProfile>();

            for (int i = 0; i < emailTo.Count(); i++)
            {
                MailProfile mail = new MailProfile()
                {
                    MailAddress = emailTo.ElementAt(i)
                };

                mailTo.Add(mail);
            }

            SendMailMessage message = new SendMailMessage();

            message.emailFrom            = ConfigurationManager.AppSettings["From"];
            message.emailFromDisplayName = ConfigurationManager.AppSettings["FromName"];
            message.emailTo      = mailTo;
            message.emailSubject = "Subject";
            message.emailBody    = fullErrorMessage;

            int intSendMailType;

            intSendMailType = int.Parse(ConfigurationManager.AppSettings["SmtpType"]);
            switch (intSendMailType)
            {
            case 1:
                message.sendBy     = SendMailMessage.SendByEnum.BrinksSmtp;
                message.smtpServer = ConfigurationManager.AppSettings["SmtpServer"];
                break;
            }

            SendMail sendMail = new SendMail();

            sendMail.MailSend(message);
        }
Exemplo n.º 11
0
        void ReportFailure(string text, ImmutableEnvelope envelope)
        {
            // we do not report failure on attempts to send mail messages
            // this could be a loop
            // we can't report them anyway (since mail sending is not available)
            // note, that this could be an indirect loop.
            if (text.Contains(typeof(SendMailMessage).Name))
                return;

            if (text.Contains(typeof(MessageQuarantined).Name))
                return;

            var name = envelope.Message.GetType().Name.Replace("Command", "");

            var subject = string.Format("[Error]: S2 fails '{0}'", name);


            var builder = new StringBuilder();
            builder.AppendFormat(
                @"<p>Support,</p><p>Something just went horribly wrong - there is a problem that I can't resolve. Please check the error log <strong>ASAP</strong>.</p>
                        <p>Here are a few details to help you out:</p><pre>");

            builder.AppendLine(WebUtility.HtmlEncode(text));

            builder.AppendFormat("</pre><p>You can use S2 Maintenance to get the error details.</p><p>Sincerely,<br /> Hub AI</p>");




            // if we don't fit in the limits
            if (text.Length >= 1024 * 1024)
            {
                const string body = "Subj, please notify Lokad support team immediately";
                const string subj = "[S2]: Quarantine overflow";
                var message = new SendMailMessage(new[] { new Email("*****@*****.**") }, subj,
                    body, false, null, null, null);
                _writer.SendCommand(message, true);
                // fail immediately

                return;
            }

            var to = new[]
                {
                    new Email("*****@*****.**", "Salescast Support"),
                    new Email("*****@*****.**", "Rinat Abdullin")
                };
            var cmd = new SendMailMessage(to, subject, builder.ToString(), true, null, null, null);
            _writer.SendCommand(cmd, true);
            var buffer = _streamer.SaveEnvelopeData(envelope);
            var names = new[] { ContractEvil.GetContractReference(envelope.Message.GetType()) };
            _writer.Publish(new MessageQuarantined(text, buffer, names, DateTime.UtcNow));
        }
Exemplo n.º 12
0
 public void Initialize(ActiveUp.Net.Common.DeltaExt.MailActions action, bool mailEditabile)
 {
     ShowPopUp();
     SendMailMessage.Initialize(action, mailEditabile);
 }
Exemplo n.º 13
0
 public void Initialize(ActiveUp.Net.Common.DeltaExt.MailActions action)
 {
     ShowPopUp();
     SendMailMessage.Initialize(action);
 }
Exemplo n.º 14
0
        public async Task SendEmailAsync(SendMailMessage mail)
        {
            Logger.Debug("Sending email");

            foreach (var recipient in mail.Recipients)
            {
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress(mail.FromName, mail.FromMail));
                message.To.Add(new MailboxAddress(recipient.ToName, recipient.ToMail));
                message.Subject = mail.Subject;

                var builder  = new BodyBuilder();
                var mailBody = mail.Body;

                var regexImgFromFile = new Regex(@"src=""cid:(?<FileName>[^,|""]*)""");
                try
                {
                    foreach (Match match in regexImgFromFile.Matches(mailBody))
                    {
                        var pathId = match.Groups["FileName"].Value;

                        var image = builder.LinkedResources.Add(pathId);
                        image.ContentId = pathId;
                    }
                }
                catch (IOException ex)
                {
                    Logger.Warn(ex, "Error while parsing image");
                }

                var regexImgFromTemplate = new Regex(@"src=""cid:(?<Cid>\w+)(?<Remove>,data:.*;base64,)(?<Image>[^""]*)");
                try
                {
                    foreach (Match match in regexImgFromTemplate.Matches(mailBody))
                    {
                        var cid  = match.Groups["Cid"].Value;
                        var data = Convert.FromBase64String(match.Groups["Image"].Value);
                        var ms   = new MemoryStream(data);

                        mailBody = mailBody.Replace(match.Groups["Remove"].Value + match.Groups["Image"], "");

                        var image = builder.LinkedResources.Add("tmp", ms);
                        image.ContentId = cid;
                    }
                }
                catch (IOException ex)
                {
                    Logger.Warn(ex, "Error while parsing image");
                }

                builder.HtmlBody = mailBody;
                message.Body     = builder.ToMessageBody();

                using (var client = new SmtpClient())
                {
                    await client.ConnectAsync(_settings.Hostname, _settings.Port, _settings.UseSsl);

                    await client.AuthenticateAsync(_settings.Username, _settings.Password);

                    await client.SendAsync(message);

                    await client.DisconnectAsync(true);
                }

                Logger.Debug("Email sent");
            }
        }
                public SendMail Build()
                {
                    string[] ToMailboxes(MailboxesBuilder builder) => builder.Mailboxes.Select(m => $"{m.Name}{UnitSeparator}{m.Address}").ToArray();

                    var sendMail = new SendMailMessage
                    {
                        Subject   = _subject,
                        From      = ToMailboxes(_from),
                        To        = ToMailboxes(_to),
                        MessageId = _messageId
                    };

                    void BuildAttachments(AttachmentsBuilder builder)
                    {
                        IList <byte[]> buffers        = new List <byte[]>();
                        IList <string> attachmentMeta = new List <string>();

                        int offset = 0;

                        foreach (var attachment in builder.Attachments)
                        {
                            int length = (int)attachment.Stream.Length;

                            var buffer = new byte[length];
                            attachment.Stream.Read(buffer, 0, length);

                            buffers.Add(buffer);
                            attachmentMeta.Add($"{attachment.FileName}{UnitSeparator}{attachment.MediaType}{UnitSeparator}{attachment.MediaSubType}{UnitSeparator}{offset}{UnitSeparator}{length}");

                            offset += length;
                        }

                        sendMail.AttachmentsContent = buffers.SelectMany(b => b).ToArray();
                        sendMail.AttachmentsMeta    = attachmentMeta.ToArray();
                    }

                    if (_withImportance.IsValueCreated)
                    {
                        sendMail.Importance = _withImportance.Value.Importance;
                    }
                    if (_withXPriority.IsValueCreated)
                    {
                        sendMail.XPriority = _withXPriority.Value.Priority;
                    }
                    if (_withPriority.IsValueCreated)
                    {
                        sendMail.Priority = _withPriority.Value.Priority;
                    }
                    if (_cc.IsValueCreated && _cc.Value.Mailboxes.Count > 0)
                    {
                        sendMail.Cc = ToMailboxes(_cc.Value);
                    }
                    if (_bcc.IsValueCreated && _bcc.Value.Mailboxes.Count > 0)
                    {
                        sendMail.Bcc = ToMailboxes(_bcc.Value);
                    }
                    if (_withAttachments.IsValueCreated)
                    {
                        BuildAttachments(_withAttachments.Value);
                    }

                    return(sendMail);
                }
Exemplo n.º 16
0
        private (MailMessageInteraction, InteractionStatusLog, List <InteractionAttachment>) ToMailMessage(SendMailMessage message)
        {
            var id = Guid.NewGuid().ToString();

            return(new MailMessageInteraction
            {
                Id = id,
                TitleText = message.Subject,
                MessageText = AddReadingLink(message.Body, id),
                ReceiverEmail = message.Email,
                SendNow = true,
                UserId = null,
                Type = EccConsts.EmailType,
                MessageDistributionId = message.MessageDistributionId
            },
                   new InteractionStatusLog
            {
                InteractionId = id,
                Status = InteractionStatus.Created,
                StartedOn = Application.DateTimeProvider.Now
            },
                   GetAttachments(id, message.AttachmentFileIds));
        }