Пример #1
0
 public async Task SendEmailNotificationToInternalUser(
     NotificationSettings activeSettings, // todo change model name to generic name
     User userFrom,
     User userTo,
     string subject,
     string message,
     params Attachment[] attachments)
 {
     await _mailerRepo.SendEmailAsync(activeSettings, userTo.FirstName, userTo.Email1, subject, message, null);
 }
Пример #2
0
 public async Task SendEmailToExternalUser(
     NotificationSettings activeSettings, // todo change model name to generic name
     string toName,
     string toEmailAddress,
     string subject,
     string message,
     params Attachment[] attachments)
 {
     await _mailerRepo.SendEmailAsync(activeSettings, toName, toEmailAddress, subject, message, null);
 }
Пример #3
0
        public async Task SendEmailMultipleReceiversAsync(
            NotificationSettings activeSettings,
            // List<string> toName,
            List <string> toEmailAddress,
            string subject,
            string message,
            params Attachment[] attachments)
        {
            var email = new MimeMessage();

            email.From.Add(new MailboxAddress(activeSettings.EmailSenderName, activeSettings.EmailSendersEmail));
            for (int i = 0; i < toEmailAddress.Count; i++)
            {
                email.To.Add(new MailboxAddress("", toEmailAddress[i]));
            }

            email.Subject = subject;

            var body = new BodyBuilder
            {
                HtmlBody = message
            };

            if (attachments != null)
            {
                foreach (var attachment in attachments)
                {
                    using (var stream = await attachment.ContentToStreamAsync())
                    {
                        body.Attachments.Add(attachment.FileName, stream);
                    }
                }
            }

            email.Body = body.ToMessageBody();


            using (var client = new SmtpClient())
            {
                //validate MailServer Certificate
                client.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
                client.AuthenticationMechanisms.Remove("XOAUTH2");

                // Start of provider specific settings
                await client.ConnectAsync(activeSettings.HostName, activeSettings.Port ?? 587, false).ConfigureAwait(false);

                await client.AuthenticateAsync(activeSettings.EmailSendersEmail, activeSettings.EmailSenderPassword).ConfigureAwait(false);

                // End of provider specific settings

                await client.SendAsync(email).ConfigureAwait(false);

                await client.DisconnectAsync(true).ConfigureAwait(false);
            }
        }
Пример #4
0
 public async Task SendSMSNotificationToInternalUser(
     NotificationSettings activeSettings, // todo change model name to generic name
     User userTo,
     string subject,
     string message)
 {
     if (activeSettings.SmsServiceProvider == SMSServiceProvider.Twilio)
     {
         _mailerRepo.SendSMSViaTwilioAsync(activeSettings, userTo, subject, message);
     }
 }
Пример #5
0
 public async Task SendEmailToMultipleInternalUsers(
     NotificationSettings activeSettings, // todo change model name to generic name
     List <string> toEmailAddress,
     string subject,
     string message,
     params Attachment[] attachments)
 {
     if (toEmailAddress.Count > 0)
     {
         await _mailerRepo.SendEmailMultipleReceiversAsync(activeSettings, toEmailAddress, subject, message, null);
     }
 }
Пример #6
0
        public void SendSMSViaTwilioAsync(
            NotificationSettings activeSettings, // todo change model name to generic name
            User userTo,
            string subject,
            string message)
        {
            string accountSid = _twilioAccountDetails.AccountSid;
            string authToken  = _twilioAccountDetails.AuthToken;
            string senderNo   = _twilioAccountDetails.SenderNo;

            TwilioClient.Init(accountSid, authToken);

            MessageResource.Create(
                body: message,
                from: new Twilio.Types.PhoneNumber(senderNo),
                to: new Twilio.Types.PhoneNumber(userTo.Phone1)
                );
        }
Пример #7
0
        public bool ValidateFileSize(NotificationSettings deptSettings, NotificationSettings orgSettings, NotificationSettings generalSettings, IFormFile file)
        {
            NotificationSettings activeSettings;
            float?MaxFileSize = 50 * 1024;

            if (deptSettings != null && deptSettings.ActivateFileSettings == true && deptSettings != null && deptSettings.MaxImageFileSize != null)
            {
                activeSettings = deptSettings;
            }
            else if (orgSettings != null && orgSettings.ActivateFileSettings == true && orgSettings != null && orgSettings.MaxImageFileSize != null)
            {
                activeSettings = orgSettings;
            }
            else
            {
                activeSettings = generalSettings;
            }
            if (activeSettings != null)
            {
                if (activeSettings.IsSupportedImageFile(file.FileName))
                {
                    if (activeSettings.MaxImageFileSize != null)
                    {
                        MaxFileSize = activeSettings.MaxImageFileSize;
                    }
                }
                else if (activeSettings.IsSupportedVideoFile(file.FileName))
                {
                    if (activeSettings.MaxVideoFileSize != null)
                    {
                        MaxFileSize = activeSettings.MaxVideoFileSize;
                    }
                }
            }

            if (file.Length < MaxFileSize)
            {
                return(true);
            }

            return(false);
        }
Пример #8
0
        public bool IsImageFileNotVideo(NotificationSettings deptSettings, NotificationSettings orgSettings, NotificationSettings generalSettings, IFormFile file)
        {
            NotificationSettings activeSettings;

            if (deptSettings != null && deptSettings.ActivateFileSettings == true && deptSettings.AcceptedImageFileTypes != null && deptSettings.AcceptedVideoFileTypes != null)
            {
                activeSettings = deptSettings;
            }
            else if (orgSettings != null && orgSettings.ActivateFileSettings == true && orgSettings.AcceptedImageFileTypes != null && orgSettings.AcceptedVideoFileTypes != null)
            {
                activeSettings = orgSettings;
            }
            else
            {
                activeSettings = generalSettings;
            }
            if (activeSettings != null)
            {
                if (activeSettings.AcceptedImageFileTypes != null)
                {
                    if (activeSettings.IsSupportedImageFile(file.FileName))
                    {
                        return(true);
                    }
                }
                if (activeSettings.AcceptedVideoFileTypes != null)
                {
                    if (activeSettings.IsSupportedVideoFile(file.FileName))
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
Пример #9
0
        public async Task <string> GetUnderReviewIncidenceNotificationMail(User assigneeUserData, User assignerUserData, EventResource incidenceData, NotificationSettings settings, OrganizationDepartment departmentData, Organization organizationData)
        {
            var msg = "Dear " + assigneeUserData?.FirstName + ", <br/><br/>The incidence with the details below is under review<br/><br/>Incidence Description: " + incidenceData?.Description + "<br/>Assigned Department: " + departmentData?.Name + "<br/>Assigned Organization: " + organizationData?.CompanyName + "<br/>Assigner: " + assignerUserData?.FirstName + " " + assignerUserData?.LastName + " (" + assignerUserData?.JobTitle + ") <br/>Assignee: " + assigneeUserData?.FirstName + " " + assigneeUserData?.LastName + " (" + assigneeUserData?.JobTitle + ") <br/><br/>IRS Automated Reports";

            return(msg);
        }
Пример #10
0
        public async Task <string> GetNewHazardNotificationMail(EventResource incidenceData, NotificationSettings settings, OrganizationDepartment ReporterDeptData)
        {
            var msg = "Dear " + settings?.EntityName + " Member" + ", <br/><br/>A new hazard with the details below has been created<br/><br/>Hazard Description: " + incidenceData?.Description + "<br/>Reporter's Name: " + incidenceData?.ReporterName + " " + "<br/>Reporter's Email: " + incidenceData?.ReporterEmail + " " + "<br/>Reporter's Department: " + ReporterDeptData?.Name + " <br/><br/>IRS Automated Reports";

            return(msg);
        }
Пример #11
0
        public async Task <string> GetClosedIncidenceNotificationExternalMail(EventResource incidenceData, NotificationSettings settings, OrganizationDepartment departmentData, Organization organizationData)
        {
            var msg = "Dear " + incidenceData?.ReporterName + ", <br/><br/>The incidence with the details below has been closed<br/><br/>Incidence Description: " + incidenceData?.Description + "<br/>Assigned Department: " + departmentData?.Name + "<br/>Assigned Orgainization: " + organizationData?.CompanyName + "<br/><br/>IRS Automated Reports";

            return(msg);
        }