Exemple #1
0
        public async Task <ServiceResult> SendEmailAsync(string ip, string toEmail, string fromEmail, string subject, string body, EmailSettings settings)
        {
            if (string.IsNullOrWhiteSpace(settings.SiteDomain))
            {
                _logger.InsertError("The  email setting site domain key is not set.", "UserManager", "SendEmail");
                return(ServiceResponse.Error("An error occured when sending the message. <br/>ERROR: Site Domain configuration."));
            }

            if (string.IsNullOrWhiteSpace(settings.SiteEmail))
            {
                _logger.InsertError("The email setting SiteEmail is not set.", "UserManager", "SendEmail");
                return(ServiceResponse.Error("An error occured when sending the message."));
            }

            string      siteEmail = settings.SiteEmail;
            MailAddress ma        = new MailAddress(siteEmail, settings.SiteDomain);
            MailMessage mail      = new MailMessage();

            mail.From = ma;
            mail.ReplyToList.Add(ma);
            mail.To.Add(toEmail);
            mail.Subject    = subject;
            mail.Body       = body;
            mail.IsBodyHtml = true;
            SMTP mailServer = new SMTP(this._connectionKey, settings);

            return(await mailServer.SendMailAsync(mail));
        }
Exemple #2
0
        //Used to resend validation email
        public async Task <ServiceResult> SendUserEmailValidationAsync(User user, string validationCode, string ipAddress, EmailSettings settings)
        {
            if (string.IsNullOrWhiteSpace(settings.SiteDomain))
            {
                return(ServiceResponse.Error("The applications site domain key is not set."));
            }

            if (string.IsNullOrWhiteSpace(settings.SiteEmail))
            {
                return(ServiceResponse.Error("The applications site email key is not set."));
            }

            #region build email from template

            string validationUrl = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mreg/code/" + validationCode;
            string oopsUrl       = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mdel/code/" + validationCode;
            // string validationUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mreg&code=" + validationCode;
            //  string oopsUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mdel&code=" + validationCode;

            DocumentManager dm     = new DocumentManager(this._connectionKey, SessionKey);
            ServiceResult   docRes = dm.GetTemplate("EmailNewMember");
            if (docRes.Status != "OK")
            {
                return(docRes);
            }

            string template = docRes.Result?.ToString();
            if (string.IsNullOrWhiteSpace(template))
            {
                _logger.InsertError("Email template is empty", "UserManager", "SendUserEmailValidationAsync");
                return(ServiceResponse.Error("Template is empty."));
            }

            template = template.Replace("[DOMAIN]", settings.SiteDomain);
            template = template.Replace("[USERNAME]", user.Name);
            template = template.Replace("[REGISTRATION_LINK]", validationUrl);
            template = template.Replace("[UNREGISTRATION_LINK]", oopsUrl);

            #endregion


            MailAddress ma   = new MailAddress(settings.SiteEmail, settings.SiteDomain);
            MailMessage mail = new MailMessage();
            mail.From = ma;
            mail.ReplyToList.Add(ma);
            mail.To.Add(user.Email?.Trim());
            mail.Subject    = settings.SiteDomain + " account registration.";
            mail.Body       = template;
            mail.IsBodyHtml = true;
            SMTP mailServer = new SMTP(this._connectionKey, settings);
            return(await mailServer.SendMailAsync(mail));
        }
Exemple #3
0
        public async Task <ServiceResult> SendUserInfoAsync(User user, string ipAddress, EmailSettings settings)
        {
            if (string.IsNullOrWhiteSpace(settings.SiteDomain))
            {
                return(ServiceResponse.Error("The applications site domain key is not set."));
            }

            if (string.IsNullOrWhiteSpace(settings.SiteEmail))
            {
                return(ServiceResponse.Error("The applications site email key is not set."));
            }

            #region build email from template
            //users/validate/type/:type/operation/:operation/code/:code
            string validationUrl = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/pwdr/code/" + user.ProviderUserKey;
            string oopsUrl       = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mdel/code/" + user.ProviderUserKey;
            // string validationUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=pwdr&code=" + user.ProviderUserKey;
            //string oopsUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mdel&code=" + user.ProviderUserKey;

            DocumentManager dm     = new DocumentManager(this._connectionKey, SessionKey);
            ServiceResult   docRes = dm.GetTemplate("UserInfoEmail");
            if (docRes.Status != "OK")
            {
                return(docRes);
            }

            string template = docRes.Result?.ToString();

            template = template.Replace("[DOMAIN]", settings.SiteDomain);
            template = template.Replace("[USERNAME]", user.Name);
            template = template.Replace("[UPDATEPASSWORD_LINK]", validationUrl);
            template = template.Replace("[UNREGISTRATION_LINK]", oopsUrl);

            #endregion


            MailAddress ma   = new MailAddress(settings.SiteEmail, settings.SiteDomain);
            MailMessage mail = new MailMessage();
            mail.From = ma;
            mail.ReplyToList.Add(ma);
            mail.To.Add(user.Email);
            mail.Subject    = settings.SiteDomain + "  Account Information";
            mail.Body       = template;
            mail.IsBodyHtml = true;
            SMTP mailServer = new SMTP(this._connectionKey, settings);
            return(await mailServer.SendMailAsync(mail));
        }
        public async Task <ServiceResult> SendMessage(Message form)//        public  ServiceResult SendMessage(Message form)
        {
            if (form == null)
            {
                return(ServiceResponse.Error("No form was posted to the server."));
            }


            form.DateSent = DateTime.UtcNow;

            bool isValidFormat = Validator.IsValidEmailFormat(form.SentFrom);

            if (string.IsNullOrWhiteSpace(form.SentFrom) || isValidFormat == false)
            {
                ServiceResponse.Error("You must provide a valid email address.");
            }

            if (string.IsNullOrWhiteSpace(form.Comment))
            {
                ServiceResponse.Error("You must provide a message.");
            }
            NetworkHelper network   = new NetworkHelper();
            string        ipAddress = network.GetClientIpAddress(this.Request);

            EmailLog emailLog = new EmailLog();

            emailLog.Message   = form.Comment + "<br/><br/><br/>Message Key:" + emailLog.UUID;
            emailLog.Subject   = form.Subject;
            emailLog.EmailFrom = form.SentFrom;
            emailLog.UUIDType += "." + form.Type;

            if (form.Type?.ToLower() != "contactus")
            {
                emailLog.EmailTo = Globals.Application.AppSetting("SiteEmail");
            }

            emailLog.DateCreated = DateTime.UtcNow;
            emailLog.IpAddress   = ipAddress;
            emailLog.Status      = "not_sent";

            if (CurrentUser != null)
            {
                emailLog.CreatedBy   = CurrentUser.UUID;
                emailLog.AccountUUID = CurrentUser.AccountUUID;
            }
            else
            {
                emailLog.CreatedBy   = "ContactUsForm";
                emailLog.AccountUUID = "ContactUsForm";
            }

            EmailLogManager emailLogManager = new EmailLogManager(Globals.DBConnectionKey);

            if (emailLogManager.Insert(emailLog).Code == 500)
            {
                return(ServiceResponse.Error("Failed to save the email. Try again later."));
            }

            EmailSettings settings = new EmailSettings();

            settings.EncryptionKey = Globals.Application.AppSetting("AppKey");
            settings.HostPassword  = Globals.Application.AppSetting("EmailHostPassword");
            settings.HostUser      = Globals.Application.AppSetting("EmailHostUser");
            settings.MailHost      = Globals.Application.AppSetting("MailHost");
            settings.MailPort      = StringEx.ConvertTo <int>(Globals.Application.AppSetting("MailPort"));
            settings.SiteDomain    = Globals.Application.AppSetting("SiteDomain");
            settings.SiteEmail     = Globals.Application.AppSetting("SiteEmail");
            settings.UseSSL        = StringEx.ConvertTo <bool>(Globals.Application.AppSetting("UseSSL"));

            MailAddress ma   = new MailAddress(form.SentFrom, form.SentFrom);
            MailMessage mail = new MailMessage();

            mail.From = ma;
            mail.ReplyToList.Add(ma);
            mail.To.Add(emailLog.EmailTo);
            mail.Subject    = emailLog.Subject;
            mail.Body       = emailLog.Message + "<br/><br/><br/>IP:" + ipAddress;
            mail.IsBodyHtml = true;
            SMTP svc = new SMTP(Globals.DBConnectionKey, settings);

            return(await svc.SendMailAsync(mail));
        }