protected void PwdRecovery_SendingMail(object sender, EventArgs e)
        {
            try
            {
                MembershipUser mu = Membership.GetUser(PasswordRecovery1.UserName);
                //string resetPwd = mu.ResetPassword();
                string emailAddress = mu.Email;
                // Lets get the user's id
                Guid userId = (Guid)Membership.GetUser(PasswordRecovery1.UserName).ProviderUserKey;

                MailUtils mailUtils = new MailUtils(Request);
                StringBuilder strBuilder = new StringBuilder();

                // Now lets create an email message
                StringBuilder emailMessage = new StringBuilder();

                if (User.IsInRole("Employee"))
                {
                    emailMessage.Append(String.Format("Dear {0},", Context.Profile.GetPropertyValue("Employee.FirstName") + " " + Context.Profile.GetPropertyValue("Employee.LastName")));
                }
                else if (User.IsInRole("Organization"))
                {
                    emailMessage.Append(String.Format("Dear {0},", Context.Profile.GetPropertyValue("Employer.FirstName") + " " + Context.Profile.GetPropertyValue("Employer.LastName")));
                }
                else
                {
                    emailMessage.Append(String.Format("Dear {0},",PasswordRecovery1.UserName));
                }
                emailMessage.Append("<br /><br />");
                emailMessage.Append(string.Format("You have recently requested to reset your password on <b>teachinVietnam.org</b>.<br /> Please click <a href='{1}/Account/RecoveryPwd.aspx?userName={0}&lang=en'>here</a> to reset your password.<br />", PasswordRecovery1.UserName, Request.Url.GetLeftPart(UriPartial.Authority)));
                emailMessage.Append("If you did not require a new password, just disregard this message and continue using your current one.");

                strBuilder.Append(mailUtils.MailHeader());
                strBuilder.Append(mailUtils.Body(emailMessage.ToString(), null, false, null, null, "en-US"));
                strBuilder.Append(mailUtils.Seperator());

                emailMessage.Clear();
                if (User.IsInRole("Employee"))
                {
                    emailMessage.Append(String.Format("Xin chào {0},", Context.Profile.GetPropertyValue("Employee.FirstName") + " " + Context.Profile.GetPropertyValue("Employee.LastName")));
                }
                else if (User.IsInRole("Organization"))
                {
                    emailMessage.Append(String.Format("Xin chào {0},", Context.Profile.GetPropertyValue("Employer.FirstName") + " " + Context.Profile.GetPropertyValue("Employer.LastName")));
                }
                else
                {
                    emailMessage.Append(String.Format("Xin chào {0},", PasswordRecovery1.UserName));
                }

                emailMessage.Append("<br /><br />");
                emailMessage.Append(string.Format("Bạn đã yêu cầu khôi phục mật khẩu trên <b>teachinVietnam.org</b>.<br /> Mời click vào <a href='{1}/Account/RecoveryPwd.aspx?userName={0}&lang=vi'>đây</a> để khôi phục lại mật khẩu.<br />", PasswordRecovery1.UserName, Request.Url.GetLeftPart(UriPartial.Authority)));
                emailMessage.Append("Nếu bạn không yêu cầu khôi phục mật khẩu, hãy bỏ qua thư này và tiếp tục sử dụng mật khẩu cũ của bạn.");

                strBuilder.Append(mailUtils.Body(emailMessage.ToString(), null, false, null, null, "vi-VN"));
                strBuilder.Append(mailUtils.MailFooter());

                Utils.SendMail(emailAddress, "TeachinVietnam - Recovery Password Confirmation", strBuilder.ToString());
            }
            catch (Exception ex)
            {
                //Response.Redirect("~/publicArea/errorpages/ErrorNetworkNotFound.aspx");
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", "<script>alert('" + ex.Message + "');</script>");
            }
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", "<script>alert('Please go to your email and follow the directions to get back your password!');</script>");
        }
Пример #2
0
        protected void SendContact_Click(object sender, EventArgs e)
        {
            try
            {
                String myConn = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
                BusinessFacade facade = new BusinessFacade(myConn);
                string latestJobId = "";

                if (Page.User.Identity.IsAuthenticated)
                {
                    if (User.IsInRole("Organization"))
                    {
                        MembershipUser mu = Membership.GetUser();
                        //Neu ma co job.
                        if (facade.GetLastestJobIdByGuid(mu.ProviderUserKey.ToString()) != null)
                        {
                            latestJobId = facade.GetLastestJobIdByGuid(mu.ProviderUserKey.ToString());
                        }
                    }
                }

                StringBuilder sb = new StringBuilder();
                string subject = txt_OrgName.Text.Trim() + " " + txt_Subject.Text.Trim();

                if (lbl_CandidateName.Text == null || lbl_CandidateName.Text == "")
                {
                    lbl_CandidateName.Text = "candidate";
                }
                MailUtils mailUtils = new MailUtils(Request);
                //header
                sb.Append(mailUtils.MailHeader());

                String title = "Dear " + lbl_CandidateName.Text + ",<br />A new message has just come from " + txt_OrgName.Text.Trim() + " via TeachinVietnam.org:";
                String body = txt_Message.Text.Trim();
                String href = "publicArea/JobDetails.aspx?jId=" + latestJobId + "&lang=en";
                String linkLabel = "Click here to examine your online resume before responding!";
                //body_en
                if (latestJobId != "")
                {
                    sb.Append(mailUtils.Body(title, body, true, href, linkLabel, "en-US"));
                }
                else
                {
                    sb.Append(mailUtils.Body(title, body, false, href, linkLabel, "en-US"));
                }
                sb.Append(mailUtils.Seperator());
                string ntd = "";
                if (User.IsInRole("Organization"))
                {
                    ntd = " nhà tuyển dụng ";
                }
                title = "Chào " + lbl_CandidateName.Text + ",<br />Bạn có thư từ " + ntd + txt_OrgName.Text.Trim() + " thông qua hệ thống TeachinVietnam:";
                href = "publicArea/JobDetails.aspx?jId=" + latestJobId + "&lang=vi";
                linkLabel = "Click vào đây để kiểm tra Hồ sơ của bạn trước khi ứng tuyển!";
                //body vi
                if (latestJobId != "")
                {
                    sb.Append(mailUtils.Body(title, body, true, href, linkLabel, "vi-VN"));
                }
                else
                {
                    sb.Append(mailUtils.Body(title, body, false, href, linkLabel, "vi-VN"));
                }

                //footer
                sb.Append(mailUtils.MailFooter());
                Guid userProviderKey = new Guid(Request.Params["cvname"].ToString());
                MembershipUser candidateMembership = Membership.GetUser(userProviderKey);

                Utils.SendMail(candidateMembership.Email, subject, sb.ToString());

                Response.Redirect("~/publicArea/CV/RequestSuccess.aspx", false);
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", "<script>alert('" + ex.Message + "');</script>");
            }
        }
        protected void SendMail_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //String builder is the body
                StringBuilder sb = new StringBuilder();

                MailUtils mailUtils = new MailUtils(Request);
                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append(mailUtils.MailHeader());

                //english content
                String href = "publicarea/JobDetails.aspx?jid=" + Dj.Id + "&lang=en";
                String linkLabel = "Click here to view this job's details";
                sb.Append("Hi " + Context.Profile.GetPropertyValue("Employee.FirstName").ToString() + " " + Context.Profile.GetPropertyValue("Employee.LastName").ToString() + ",<br /><br /> ");
                sb.Append("You have successfully applied for the job.<br />");
                sb.Append(String.Format("<table style='margin-left:25px;'><tr><td style='padding: 8px;background: #d0dafd; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>Job Title:</td><td style='padding: 8px;background: #e8edff; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>{0}</td></tr><tr><td style='padding: 8px;background: #d0dafd; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>Organization:</td><td style='padding: 8px;background: #e8edff; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>{1}</td></tr><tr><td style='padding: 8px;background: #d0dafd; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>Job Details:</td><td style='padding: 8px;background: #e8edff; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'><a style='text-decoration: none; color: #86ac3d;' href='{2}/{3}'> &raquo; {4}</a></td></tr></table>", Dj.Title, Dj.OrgName, Request.Url.GetLeftPart(UriPartial.Authority), href, linkLabel));

                strBuilder.Append(mailUtils.Body(sb.ToString(), null, false, href, linkLabel, "en-US"));
                strBuilder.Append(mailUtils.Seperator());
                //Vietnamese content.
                href = "publicarea/JobDetails.aspx?jid=" + Dj.Id + "&lang=vi";
                linkLabel = "Mời bạn click vào đây để xem thông tin công việc.";
                sb.Clear();
                sb.Append("Chào " + Context.Profile.GetPropertyValue("Employee.FirstName").ToString() + " " + Context.Profile.GetPropertyValue("Employee.LastName").ToString() + ",<br /><br /> ");
                sb.Append("Bạn vừa ứng tuyển thành công! <br />");
                sb.Append(String.Format("<table style='margin-left:25px;'><tr><td style='padding: 8px;background: #d0dafd; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>Vị trí:</td><td style='padding: 8px;background: #e8edff; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>{0}</td></tr><tr><td style='padding: 8px;background: #d0dafd; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>Tổ chức:</td><td style='padding: 8px;background: #e8edff; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>{1}</td></tr><tr><td style='padding: 8px;background: #d0dafd; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'>Job Details:</td><td style='padding: 8px;background: #e8edff; border-bottom: 1px solid #fff;color: #669;border-top: 1px solid transparent;'><a style='text-decoration: none; color: #86ac3d;' href='{2}/{3}'> &raquo; {4}</a></td></tr></table>", Dj.Title, Dj.OrgName, Request.Url.GetLeftPart(UriPartial.Authority), href, linkLabel));

                strBuilder.Append(mailUtils.Body(sb.ToString(), null, false, href, linkLabel, "vi-VN"));

                strBuilder.Append(mailUtils.MailFooter());

                //--- Employer side
                StringBuilder sr = new StringBuilder();
                sr.Append(mailUtils.MailHeader());

                String title = string.Format("Hi {0},<br />Here is {1}'s application for <b>{2}</b><br />", Dj.Contact, txt_FullName.Text, lbl_JobTitle.Text);
                title += string.Format("On {0:ddd, MMM dd, yyyy} at {1}, {2} &lt;{3}&gt; wrote:<hr />", DateTime.Now, DateTime.Now.ToShortTimeString(), txt_FullName.Text, lbl_YourMail.Text);

                String body = HttpUtility.HtmlDecode(txtMessage.Text.Replace(Environment.NewLine, "<br />"));
                sr.Append(mailUtils.Body(title, body, false));
                sr.Append(mailUtils.MailFooter());

                try
                {
                    //notify recruiter that this userid has applied for his job. Build the table like app managemt like candidate.
                    SendMail(Dj.EmailForEmployer, sr.ToString(), true);

                    //To the candidate
                    SendMail(lbl_YourMail.Text, strBuilder.ToString(), false);
                    facade.SaveAJob(UserId, JId, txt_FullName.Text);

                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script>window.location.href='finish-apply.aspx?org="+Dj.OrgName+"';</script>");
                    if (sent)
                    {
                        Response.Redirect("finish-apply.aspx?org=" + Dj.OrgName);
                    }
                    else
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", "<script>alert('Your application is not sent.\nPlease try again.');</script>");
                    }
                }
                catch (SmtpException)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", "<script>alert('Your email is not existed or there would be problem with your internet connection.\nPlease try again.');</script>");
                }
                catch (Exception ex)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", "<script>alert('" + ex.Message + "');</script>");
                }
                finally
                {
                    string[] filePaths = Directory.GetFiles(Server.MapPath("~/temp/" + UserId + "/"), "*.*",
                                            SearchOption.AllDirectories);
                    foreach (string path in filePaths)
                    {
                        File.Delete(path);
                    }
                }
            }
        }