public async Task <int> InviteIndividualUser(CompanyUsersRequest usersRequest, HttpContext context)
        {
            try
            {
                int  returnResult = 0;
                bool emailExist   = await this.authRepo.EmailExist(usersRequest.Email);

                if (emailExist)
                {
                    returnResult = 2;
                    return(returnResult); // Email Exist
                }
                else
                {
                    Guid            guid       = Guid.NewGuid();
                    InviteUsersList inviteUser = new InviteUsersList();
                    inviteUser.EmailAddress    = usersRequest.Email;
                    inviteUser.ActivationToken = guid;
                    InviteEmailData response = await this.commonEmailsService.SendUserInviteEmails(inviteUser, context);

                    if (response.InviteStatus == 1)
                    {
                        returnResult = await this._companyRepo.InviteIndividualUser(usersRequest, guid);
                    }
                }
                return(returnResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task <InviteEmailData> SendUserInviteEmails(InviteUsersList emailData, HttpContext context)
        {
            bool            status          = false;
            InviteEmailData response        = new InviteEmailData();
            string          strEmailSubject = string.Empty;

            strEmailSubject = _iconfiguration.GetValue <string>("AuthMessageSenderOptions:WelcomeEmail");

            string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images\sessionsLogoBlack.png"}";

            try
            {
                string directory = $"{Directory.GetCurrentDirectory()}{@"\wwwroot"}";
                var    emailHtml = System.IO.File.ReadAllText(directory + "/Templates/Invite_Company_Members.html");
                emailHtml = emailHtml.Replace("{{ActivationToken}}", emailData.ActivationToken.ToString());
                var    membersignupURL = _iconfiguration.GetValue <string>("AuthMessageSenderOptions:MemberSignupUrl");
                string logoPath        = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase + "//images//sessionsLogoBlack.png";
                string newsletter      = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase + "//images//newsletter.png";
                response.EmailSubject = strEmailSubject;
                response.EmailSender  = _iconfiguration.GetValue <string>("AuthMessageSenderOptions:SendGridEmail");
                response.EmailBody    = emailHtml;
                response.InviteStatus = 1;
                emailHtml             = emailHtml.Replace("{{logo}}", logoPath);
                emailHtml             = emailHtml.Replace("{{newsletter}}", newsletter);
                emailHtml             = emailHtml.Replace("{{membersignupURL}}", membersignupURL);

                await _iEmailSenderService.SendEmailAsync(_iconfiguration.GetValue <string>("AuthMessageSenderOptions:SendGridEmail"), emailData.EmailAddress, strEmailSubject, emailHtml);

                status = true;
                if (status == true)
                {
                    response.InviteStatus = 1;
                }
                else
                {
                    response.InviteStatus = 100;
                }
                return(response);
            }
            catch (Exception ex)
            {
                response.InviteStatus = 100;
                return(response);
            }
        }
        public async static Task <bool> SendEmails(string subject, string EmailBody, string EmailFrom, string emailto)
        {
            // String FROM = "*****@*****.**";
            // String FROMNAME = "*****@*****.**";
            // String TO = "*****@*****.**";
            var    response      = new InviteEmailData();
            String SMTP_USERNAME = "******"; //from
            String SMTP_PASSWORD = "******";
            String CONFIGSET     = "ConfigSet";
            String HOST          = "email-smtp.us-west-2.amazonaws.com";

            int PORT = 587;

            String BODY = EmailBody;
            // Create and build a new MailMessage object
            MailMessage message = new MailMessage();

            message.IsBodyHtml = true;
            message.From       = new MailAddress(EmailFrom);
            message.To.Add(new MailAddress(emailto));
            message.Subject = subject;
            message.Body    = BODY;
            // Comment or delete the next line if you are not using a configuration set
            message.Headers.Add("X-SES-CONFIGURATION-SET", CONFIGSET);
            using (var client = new System.Net.Mail.SmtpClient(HOST, PORT))
            {
                // Pass SMTP credentials
                client.Credentials =
                    new NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);
                // Enable SSL encryption
                client.EnableSsl             = true;
                client.UseDefaultCredentials = false;
                // Try to send the message. Show status in console.
                try
                {
                    client.Send(message);
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
        }
        public async Task <bool> SendInvitationEmails(HttpContext context)
        {
            try
            {
                IEnumerable <InviteUsersList> list = await _jobsRepo.GetInviteUsers();

                if (list != null && list.Count() > 0)
                {
                    foreach (var email in list)
                    {
                        //  string url = "http://52.25.96.244:7051/Company/MemberSignup/" + email.ActivationToken;
                        InviteEmailData response = await this.commonEmailsService.SendUserInviteEmails(email, context);

                        response.UserInviteGuId = email.UserInviteGuId;
                        await _jobsRepo.UpdateUserInvitationStatus(response);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public async Task <IEnumerable <bool> > UpdateUserInvitationStatus(InviteEmailData data)
        {
            try
            {
                IEnumerable <bool> status;
                using (IDbConnection con = new SqlConnection(_connectionString))
                {
                    status = await con.QueryAsync <bool>("dbo.SSP_UpdateUserInvitationStatus", new
                    {
                        UserInviteGuId = data.UserInviteGuId,
                        EmailSender    = data.EmailSender,
                        EmailBody      = data.EmailBody,
                        InviteStatus   = data.InviteStatus,
                        EmailSubject   = data.EmailSubject
                    }, commandType : CommandType.StoredProcedure);
                }

                return(status);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }