コード例 #1
0
        /// <summary>
        /// Отправлет сообщение на указаный адрес.
        /// </summary>
        /// <param name="recipient">Получатель или получатели.</param>
        /// <param name="title">Заголовок.</param>
        /// <param name="body">Тело сообщения.</param>
        /// <param name="attachments">Список вложений.</param>
        public void Send(string recipient, string title, string body, IList <KeyValuePair <string, byte[]> > attachments)
        {
            var logger = StartEnumServer.Instance.GetLogger();

            try
            {
                var settings = StartEnumServer.Instance.GetSettings <IMailingServiceSettings>();

                logger.LogInfo <MailingService>($"Старт отправки email сообщения \"{title}\" для \"{recipient}\" ");
                var smtpClient = new SmtpClient(settings.Host,
                                                settings.Port);
                smtpClient.EnableSsl   = settings.UseSsl;
                smtpClient.Credentials = new NetworkCredential(settings.Login, settings.Password);
                var message = new MailMessage();

                message.IsBodyHtml = false;
                //message.BodyEncoding = Encoding.Default;

                message.To.Add(recipient);

                var messageFrom = new MailAddress(settings.Login);
                message.From = messageFrom;

                message.Body    = body;
                message.Subject = title;

                if (attachments != null)
                {
                    foreach (var attachment in attachments)
                    {
                        var attach = AttachmentHelper.CreateAttachment(new MemoryStream(attachment.Value), attachment.Key,
                                                                       TransferEncoding.Base64);
                        message.Attachments.Add(attach);
                    } //foreach
                }

                smtpClient.Send(message);
                message.Dispose();
                smtpClient.Dispose();
                logger.LogInfo <MailingService>(
                    $"Сообщение  \"{title}\" для \"{recipient}\" успешно отправлено.");
            }
            catch (SmtpException ex)
            {
                string inner = string.Empty;
                if (ex.InnerException != null)
                {
                    inner = ex.InnerException.Message;
                }
                logger.LogError <MailingService>(
                    $"Во время отправки1 сообщения {body} \"{title}\" для \"{recipient}\" произошла ошибка {ex.GetType()} {ex.Message} |{inner} |{ex.StackTrace}");
            }
        }
コード例 #2
0
ファイル: MailingService.cs プロジェクト: alexs0ff/remboard
        /// <summary>
        /// Отправлет сообщение на указаный адрес.
        /// </summary>
        /// <param name="recipient">Получатель или получатели.</param>
        /// <param name="title">Заголовок.</param>
        /// <param name="body">Тело сообщения.</param>
        /// <param name="attachments">Список вложений.</param>
        public void Send(string recipient, string title, string body, IList <KeyValuePair <string, byte[]> > attachments)
        {
            try
            {
                _logger.InfoFormat("Старт отправки email сообщения \"{0}\" для \"{1}\" ", title, recipient);
                var smtpClient = new SmtpClient(MailingServiceConfiguration.Settings.Host,
                                                MailingServiceConfiguration.Settings.Port);
                smtpClient.EnableSsl   = MailingServiceConfiguration.Settings.UseSsl;
                smtpClient.Credentials = new NetworkCredential(MailingServiceConfiguration.Settings.Login,
                                                               MailingServiceConfiguration.Settings.Password);
                var message = new MailMessage();

                message.IsBodyHtml = false;
                //message.BodyEncoding = Encoding.Default;

                message.To.Add(recipient);

                var messageFrom = new MailAddress(MailingServiceConfiguration.Settings.Login);
                message.From = messageFrom;

                message.Body    = body;
                message.Subject = title;

                foreach (var attachment in attachments)
                {
                    var attach = AttachmentHelper.CreateAttachment(new MemoryStream(attachment.Value), attachment.Key,
                                                                   TransferEncoding.Base64);
                    message.Attachments.Add(attach);
                } //foreach

                smtpClient.Send(message);
                message.Dispose();
                smtpClient.Dispose();
                _logger.InfoFormat(
                    "Сообщение  \"{0}\" для \"{1}\" успешно отправлено.", title,
                    recipient);
            }
            catch (SmtpException ex)
            {
                string inner = string.Empty;
                if (ex.InnerException != null)
                {
                    inner = ex.InnerException.Message;
                }
                _logger.ErrorFormat(
                    "Во время отправки1 сообщения {0} \"{1}\" для \"{2}\" произошла ошибка {3} {4} |{5} |{6}", body,
                    title, recipient, ex.GetType(), ex.Message,
                    inner, ex.StackTrace);
            }
        }
コード例 #3
0
        protected override void InternalCopyFromModified(IProperty srcProperty)
        {
            Item item = base.XsoItem as Item;

            if (item == null)
            {
                AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, null, "XSO16AttachmentProperty:InternalCopyFromModified. msgItem can not be null.");
                throw new UnexpectedTypeException("Item", base.XsoItem);
            }
            IAttachments12Property attachments12Property = srcProperty as IAttachments12Property;

            if (attachments12Property == null)
            {
                throw new UnexpectedTypeException("IAttachments12Property", srcProperty);
            }
            new List <IAttachment>(attachments12Property.Count);
            List <string> list = new List <string>();

            foreach (Attachment12Data attachment12Data in attachments12Property)
            {
                Attachment16Data attachment16Data = attachment12Data as Attachment16Data;
                if (attachment16Data == null)
                {
                    throw new UnexpectedTypeException("Attachment16Data", attachment12Data);
                }
                if (attachment16Data.ChangeType == AttachmentAction.Delete)
                {
                    list.Add(attachment16Data.FileReference);
                }
            }
            if (list.Count > 0)
            {
                AttachmentHelper.DeleteAttachments(item, list);
            }
            foreach (Attachment12Data attachment12Data2 in attachments12Property)
            {
                Attachment16Data attachment16Data2 = attachment12Data2 as Attachment16Data;
                if (attachment16Data2 == null)
                {
                    throw new UnexpectedTypeException("Attachment16Data", attachment12Data2);
                }
                if (attachment16Data2.ChangeType == AttachmentAction.Add)
                {
                    AttachmentHelper.CreateAttachment(item, attachment16Data2);
                }
            }
        }
コード例 #4
0
        /// <summary> 夾帶寄信 </summary>
        /// <param name="fileName"></param>
        private void SendMailing(string fileName)
        {
            try
            {
                var sendmail = new SendMail(reportSetting, mailSetting);
                var subject  = fileName;
                var msg      = "請參閱附件,謝謝";

                Attachment file =
                    AttachmentHelper.CreateAttachment(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, reportSetting.ExportPH, fileName), fileName, TransferEncoding.Base64);
                sendmail.send_email(msg, subject, mailSetting.MailTo, mailSetting.Mailcc, mailSetting.MailBcc, file);
            }
            catch (Exception ex)
            {
                writeLog(ex.ToString());
            }
        }
コード例 #5
0
        /// <summary>
        /// Добавление вложенного файла
        /// </summary>
        /// <param name="stream">поток данных</param>
        /// <param name="name">имя вложения</param>
        public void AddAttach(Stream stream, string name)
        {
            Attachment attach = AttachmentHelper.CreateAttachment(stream, name, TransferEncoding.Base64);

            _message.Attachments.Add(attach);
        }
コード例 #6
0
        public JsonResult SaveFilePdf(IEnumerable <HttpPostedFileBase> attachmentPost)
        {
            int res = 0;

            foreach (var file in attachmentPost)
            {
                if (file.ContentLength > 0)
                {
                    String FileExt = Path.GetExtension(file.FileName).ToUpper();


                    if (FileExt == ".PDF")
                    {
                        //string title_temp = Convert.ToString(Request["title"]);
                        //string fileClabe = Convert.ToString(Request["fileClabe"]);
                        //string title =  fileClabe + Path.GetExtension(file.FileName);

                        string title        = file.FileName;
                        int    idAttachment = 0;

                        string _path = Path.Combine(Server.MapPath("~/UploadedFiles/attachments/"), title);
                        file.SaveAs(_path);

                        Attachment attachment = new Attachment()
                        {
                            AttachmentName      = title,
                            AttachmentDirectory = "~/UploadedFiles/attachments/" + title,
                            AttachmentActive    = "1",
                        };

                        AttachmentHelper at = new AttachmentHelper();
                        //save references attachment
                        idAttachment = at.CreateAttachment(attachment);

                        if (idAttachment == 0)
                        {
                            logger.Error("Error al intentar guardar el registro la información del documento en la db. " + Environment.NewLine + DateTime.Now);
                        }
                        if (idAttachment != 0)
                        {
                            int idTag    = Convert.ToInt32(Request["idTag"]);
                            int idParent = Convert.ToInt32(Request["idParent"]);
                            int idDepto  = Convert.ToInt32(Request["idDepto"]);

                            //create relationship
                            res = at.CreateRelationAttachment(idTag, idParent, idDepto, idAttachment);
                        }
                    }
                }
            }

            if (res == 1)
            {
                model = (SessionModel)this.Session["SessionData"];

                logger.Info("Documento guardado for username: "******"El Documento se guardo correctamente." }));
            }
            else
            {
                logger.Error("Error al intentar guardar la información del documento en la db. " + Environment.NewLine + DateTime.Now);
                return(Json(new { success = false, msgError = "La información del documento no se pudo guardar." }));
            }
        }