Esempio n. 1
0
        public void NewsmailInsert(Email entity)
        {
            // Check permission: admin
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permAdmin.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            if (entity.ID.IsNull) throw new ArgumentNullException("Email.ID", "A hírlevél azonosítója nincs megadva.");
            if (entity.Subject.Length == 0)
              throw new ArgumentNullException("Email.Subject", "A hírlevél tárgya nincs megadva.");
            if (entity.MailBody.Length == 0)
              throw new ArgumentNullException("Email.MailBody", "A hírlevél szövege nincs megadva.");

            // Save data
            entity.Category = EmailCategory.Newsmail;
            m_DataContext.BeginNestedTran();

            EmailAttachmentService attSrv = new EmailAttachmentService(m_DataContext);

            try
            {
              base.EmailInsert(entity);
              // Files
              foreach (EmailAttachment attach in entity.EmailAttachments.Current)
              {
            attSrv.EmailAttachmentInsert(attach);
              }

              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }
            BusinessAuditEvent.Success(
              new EventParameter("EmailID", entity.ID),
              new EventParameter("EmailSubject", entity.Subject)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("EmailID", entity.ID),
              new EventParameter("EmailSubject", entity.Subject)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends an e-mail via SMTP.
        /// </summary>
        /// <param name="entity">Email entity to send</param>
        public void Send(Email entity)
        {
            MailMessage mailMessage = new MailMessage();
              mailMessage.From = Configuration.MailFrom;

              //entity.To = "[email protected];[email protected];";

              //mailMessage.Bcc = entity.To;
              if (entity.Cc.Length > 0)
              {
            mailMessage.Cc = entity.Cc;
              }
              mailMessage.Subject = entity.Subject;
              mailMessage.Body = entity.MailBody;
              mailMessage.BodyFormat = MailFormat.Text;
              mailMessage.BodyEncoding = Encoding.UTF8;
              entity.EmailAttachments = base.SelectChildrenByAttachmentOfEmail(entity.ID);

              //
              // A csatolt file-ok küldéséhez egy  könyvtat hozunk létre és majd ide másoljuk a
              // levélhez csatolandó file-okat
              //
              string sendEmailTempDirPath = "EmailAttachments";
              string fileDir = Path.Combine(Configuration.FileStoreFolder, "Emails\\" + entity.ID.Value.ToString());
              DirectoryInfo di = new DirectoryInfo(fileDir);

              di.CreateSubdirectory(sendEmailTempDirPath);

              foreach (EmailAttachment attachment in entity.EmailAttachments.All)
              {
            string fileFullPath = Path.Combine(fileDir, attachment.ID.Value.ToString());

            //
            // Átmásoljuk és átnevezzük a file-okat
            //
            EmailAttachmentService s = new EmailAttachmentService();
            EmailAttachment ea = s.EmailAttachmentSelect(attachment.ID);

            string sendFileFullPath = Path.Combine(fileDir, Path.Combine(sendEmailTempDirPath, ea.Path));
            string fileExtension = ea.Path.Substring(ea.Path.LastIndexOf("."));

            // File-ok másolása ...
            File.Copy(fileFullPath + fileExtension, sendFileFullPath, true);

            MailAttachment mailAttachment = new MailAttachment(sendFileFullPath);
            mailMessage.Attachments.Add(mailAttachment);
              }

              // TODO: ReplyTo mezot így lehet kitölteni
              // Ezt a konfigba is ki kell vezetni
              //mailMessage.Headers.Add( "Reply-To", "*****@*****.**");

              // elmentjük az entitást ... sikertelen küldé esetére
              base.EmailUpdate(entity);
            #if (!DEBUG)
              //
              // A spamszűrés elkerülése érdekében egyessével küldjük ki az e-mail-eket
              //
              SmtpMail.SmtpServer = Configuration.SmtpServer;
              string origSendTo = entity.To;
              string[] sendTo = origSendTo.Split(';');

              for (int i = 0; i < sendTo.Length; i++)
              {
            if (sendTo[i] != "")
            {
              mailMessage.To = sendTo[i];

              SmtpMail.Send(mailMessage);

            }
              }
            #endif
        }
Esempio n. 3
0
        public new void EmailUpdate(Email entity)
        {
            // Check permission: admin
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permAdmin.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            if (entity.Subject.Length == 0)
              throw new ArgumentNullException("Email.Subject", "A hírlevél tárgya nincs megadva.");
            if (entity.MailBody.Length == 0)
              throw new ArgumentNullException("Email.MailBody", "A hírlevél szövege nincs megadva.");

            // Logical checks
            Email selected = base.EmailSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik hírlevél.");
            if (!selected.Category.Equals(EmailCategory.Newsmail))
              throw new ApplicationException("Csak hírlevél kategóriájú levél módosítható.");

            // Save data
            selected.Subject = entity.Subject;
            selected.MailBody = entity.MailBody;
            selected.ActivityAll = entity.ActivityAll;
            selected.ActivityOther = entity.ActivityOther;
            selected.ActivityPrevention = entity.ActivityPrevention;
            selected.ActivityRehabilitation = entity.ActivityRehabilitation;
            selected.ActivityResearch = entity.ActivityResearch;
            selected.ActivityNDI = entity.ActivityNDI;
            selected.To = entity.To;

            EmailAttachmentService attSrv = new EmailAttachmentService(m_DataContext);

            m_DataContext.BeginNestedTran();
            try
            {
              // Clear old files:
              EmailAttachmentContainer oldFiles = base.SelectChildrenByAttachmentOfEmail(entity.ID);
              foreach (EmailAttachment oldFile in oldFiles.All)
              {
            attSrv.EmailAttachmentDelete(oldFile);
              }

              // EmailAttachments - insert:
              foreach (EmailAttachment file in  entity.EmailAttachments.Current)
              {
            attSrv.EmailAttachmentInsert(file);
              }
              base.EmailUpdate(selected);
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }
            BusinessAuditEvent.Success(
              new EventParameter("EmailID", entity.ID),
              new EventParameter("EmailSubject", entity.Subject)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("EmailID", entity.ID),
              new EventParameter("EmailSubject", entity.Subject)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }