Esempio n. 1
0
        private EmailContent GetEmailContent(EmailModel model)
        {
            var emailContent = new EmailContent();
            switch (model.EmailType)
            {
                case EmailTypes.RegisteredSuccessfully:
                    emailContent.Header = "Registrierung bei EventCorp";
                    emailContent.Body = "Vielen Dank, dass sich sich für uns entschieden haben"; 
                    break;
                case EmailTypes.Subscribed:

                    break;
                case EmailTypes.Unsubscribed:
                    break;
                case EmailTypes.ChangedUserData:
                    break;
                case EmailTypes.ChangedPassword:
                    break;
                case EmailTypes.UserRegistered:
                    break;
                case EmailTypes.EventCreated:
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return emailContent;
        }
Esempio n. 2
0
        public async Task<bool> SendEmail(string template, string mailTo, string subject, object model)
        {
            var content = new EmailContent
            {
                HtmlText = templateExecutor.Execute(template + ".cshtml", model),
                PlainText = templateExecutor.Execute(template + ".txt", model)
            };

            var message = messageCreator.Create(mailTo, subject, content);

            return await sender.SendAsync(message);
        }
        public async Task<bool> SendPasswordResetRequest(string emailAddress, string passwordResetUrl)
        {
            var model = new
            {
                PasswordResetUrl = passwordResetUrl,
            };

            EmailContent content = new EmailContent()
            {
                HtmlText = templateExecutor.Execute("PasswordResetRequest.cshtml", model),
                PlainText = templateExecutor.Execute("PasswordResetRequest.txt", model)
            };

            using (MailMessage message = messageCreator.Create(emailAddress,
                 "Reset your WEEE password", content))
            {
                return await sender.SendAsync(message);
            }
        }
        public async Task<bool> SendActivateUserAccount(string emailAddress, string activationUrl)
        {
            var model = new
            {
                ActivationUrl = activationUrl,
            };

            EmailContent content = new EmailContent()
            {
                HtmlText = templateExecutor.Execute("ActivateUserAccount.cshtml", model),
                PlainText = templateExecutor.Execute("ActivateUserAccount.txt", model)
            };

            using (MailMessage message = messageCreator.Create(emailAddress,
                 "Activate your WEEE user account", content))
            {
                return await sender.SendAsync(message);
            }
        }
        public async Task<bool> SendOrganisationUserRequest(string emailAddress, string organisationName)
        {
            var model = new
            {
                OrganisationName = organisationName,
                ExternalUserLoginUrl = configuration.ExternalUserLoginUrl,
            };

            EmailContent content = new EmailContent()
            {
                HtmlText = templateExecutor.Execute("OrganisationUserRequest.cshtml", model),
                PlainText = templateExecutor.Execute("OrganisationUserRequest.txt", model)
            };

            using (MailMessage message = messageCreator.Create(emailAddress,
                 "New request to access your organisation", content))
            {
                return await sender.SendAsync(message);
            }
        }
        public async Task<bool> SendOrganisationUserRequestCompleted(Domain.Organisation.OrganisationUser organisationUser)
        {
            var model = new
            {
                OrganisationName = organisationUser.Organisation.OrganisationName,
                Approved = organisationUser.UserStatus == UserStatus.Active,
                ExternalUserLoginUrl = configuration.ExternalUserLoginUrl
            };

            EmailContent content = new EmailContent()
            {
                HtmlText = templateExecutor.Execute("OrganisationUserRequestCompleted.cshtml", model),
                PlainText = templateExecutor.Execute("OrganisationUserRequestCompleted.txt", model)
            };

            using (MailMessage message = messageCreator.Create(organisationUser.User.Email,
                "Your request to access a WEEE organisation", content))
            {
                return await sender.SendAsync(message);
            }
        }
        public async Task<bool> SendOrganisationContactDetailsChanged(string emailAddress, string schemeName)
        {
            var model = new
            {
                SchemeName = schemeName
            };

            EmailContent content = new EmailContent
            {
                HtmlText = templateExecutor.Execute("OrganisationContactDetailsChanged.cshtml", model),
                PlainText = templateExecutor.Execute("OrganisationContactDetailsChanged.txt", model)
            };

            var subject = string.Format("Change of contact details for {0}", schemeName);

            using (MailMessage message = messageCreator.Create(emailAddress, subject, content))
            {
                return await sender.SendAsync(message, true);
            }
        }
        public async Task<bool> SendTestEmail(string emailAddress)
        {
            EmailContent content = new EmailContent
            {
                HtmlText = templateExecutor.Execute("Test.cshtml", null),
                PlainText = templateExecutor.Execute("Test.txt", null)
            };

            using (MailMessage message = messageCreator.Create(emailAddress, "Test email from WEEE", content))
            {
                return await sender.SendAsync(message, false);
            }
        }
        public async Task<bool> SendInternalUserAccountActivated(string emailAddress, string userFullName, string userEmailAddress, string viewUserLink)
        {
            var model = new
            {
                EmailAddress = userEmailAddress,
                FullName = userFullName,
                ViewUserLink = viewUserLink
            };

            EmailContent content = new EmailContent
            {
                HtmlText = templateExecutor.Execute("InternalUserAccountActivated.cshtml", model),
                PlainText = templateExecutor.Execute("InternalUserAccountActivated.txt", model)
            };

            using (MailMessage message = messageCreator.Create(emailAddress, "New internal user request", content))
            {
                return await sender.SendAsync(message, true);
            }
        }
        public async Task<bool> SendSchemeDataReturnSubmitted(string emailAddress, string schemeName, int complianceYear, int quarter, bool isResubmission)
        {
            var model = new
            {
                SchemeName = schemeName,
                ComplianceYear = complianceYear,
                Quarter = quarter,
                IsResubmission = isResubmission
            };

            EmailContent content = new EmailContent
            {
                HtmlText = templateExecutor.Execute("SchemeDataReturnSubmitted.cshtml", model),
                PlainText = templateExecutor.Execute("SchemeDataReturnSubmitted.txt", model)
            };

            using (MailMessage message = messageCreator.Create(emailAddress,
                string.Format("Data return submission for {0}", schemeName), content))
            {
                return await sender.SendAsync(message, true);
            }
        }
        public async Task<bool> SendSchemeMemberSubmitted(string emailAddress, string schemeName, int complianceYear, int numberOfWarnings)
        {
            var model = new
            {
                SchemeName = schemeName,
                ComplianceYear = complianceYear,
                NumberOfWarnings = numberOfWarnings
            };

            EmailContent content = new EmailContent
            {
                HtmlText = templateExecutor.Execute("SchemeMemberSubmitted.cshtml", model),
                PlainText = templateExecutor.Execute("SchemeMemberSubmitted.txt", model)
            };

            using (MailMessage message = messageCreator.Create(emailAddress,
                string.Format("Member registration submission for {0}", schemeName), content))
            {
                return await sender.SendAsync(message, true);
            }
        }
Esempio n. 12
0
        public bool SendEmail(string ToAddress, EmailContent objContent, string CC)
        {
            try
            {

                String strSMTPUsername = System.Configuration.ConfigurationManager.AppSettings["MailUsername"];
                String strSMTPPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"];

                SmtpClient objSmtpClient = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["SMTPHost"]);
                String strFromAddress = System.Configuration.ConfigurationManager.AppSettings["DefaultMailFrom"];
                String strDefaultMailRecipient = System.Configuration.ConfigurationManager.AppSettings["DebugRecipient"];
                MailMessage objMailMessage = new MailMessage();
                MailAddress objFromMailAddress = new MailAddress(strFromAddress);
                String strEmailTemplate = "";

                if (strSMTPUsername.Length > 0 && strSMTPPassword.Length > 0)
                {
                    objSmtpClient.UseDefaultCredentials = false;
                    objSmtpClient.Credentials = new NetworkCredential(strSMTPUsername, strSMTPPassword);
                }
                if (objContent.EmailTemplatePathLocal.Length > 0)
                {
                    strEmailTemplate = ReadFile(objContent.EmailTemplatePathLocal);
                    strEmailTemplate = strEmailTemplate.Replace("[ServerPath]", objContent.ImageHostDomain);
                    strEmailTemplate = strEmailTemplate.Replace("[Greeting]", objContent.Greeting);
                    strEmailTemplate = strEmailTemplate.Replace("[PartingComments]", objContent.PartingComments);
                    strEmailTemplate = strEmailTemplate.Replace("[FooterText]", objContent.FooterText);
                    strEmailTemplate = strEmailTemplate.Replace("[BodyText]", objContent.BodyText);
                }
                else
                {
                    strEmailTemplate = "<p>" + objContent.Greeting + "</p>" +
                                        "<p>" + objContent.BodyText + "</p>" +
                                        "<p>" + objContent.PartingComments + "</p>" +
                                        "<p>" + objContent.FooterText + "</p>";
                }

                if (ToAddress.IndexOf(",") > -1)
                {
                    string[] arrAddresses = ToAddress.Split(',');
                    foreach (string strAddress in arrAddresses)
                    {
                        if (strAddress.Trim().Length > 0)
                        {
                            objMailMessage.To.Add(strAddress.Trim());
                        }
                    }
                }
                else
                {
                    if (ToAddress.Length > 0)
                    {
                        objMailMessage.To.Add(ToAddress);
                    }
                    else
                    {
                        objMailMessage.To.Add(strDefaultMailRecipient);
                    }
                }
                if (CC.Length > 0)
                {
                    foreach (string strCCEmail in CC.Split(','))
                    {
                        objMailMessage.Bcc.Add(new MailAddress(strCCEmail));
                    }
                }
                objMailMessage.From = objFromMailAddress;
                objMailMessage.Subject = objContent.Subject;
                objMailMessage.Body = strEmailTemplate;
                objMailMessage.IsBodyHtml = true;

                objSmtpClient.Send(objMailMessage);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }