1

我的任务是在 asp.net c# 中构建休假管理应用程序,当员工填写所需的详细信息并按下申请按钮时,在休假申请中,邮件应发送给相应的经理说

“您好{经理},

{LoggedInUser} 已为 {NumofDays} 请求 {TypeofLeave} 请登录门户以接受或拒绝它

谢谢你。”

我可以收到邮件,但我需要的是代替 {Manager}、{TypeoLeave}、{NumofDays} 和 {LoggedInUser} 我需要各自的经理姓名、登录用户以及员工申请的休假类型和多少天。它应该从数据库中提取。

例如:“你好 ABC,

XYZ 已请病假 5 天请登录门户接受或拒绝

谢谢你。”

现在我得到与上面相同的结构。

请帮我。

protected void BtnApply_Click(object sender, EventArgs e)
    {
        MTMSDTO objc = new MTMSDTO();

        int Flag = 0;

        LblLogdInUser.Text = Session["EmpName"].ToString();
        objc.LoggedInUser = LblLogdInUser.Text;
        objc.TypeofLeave = DrpTypeofLeave.SelectedItem.Text;

        string date;
        date = Convert.ToDateTime(TxtBeginDate.Text).ToString("dd/MM/yyyy");

        DateTime dt = new DateTime();
        dt = Convert.ToDateTime(date);

        objc.BeginDate = dt;
        objc.EndDate = Convert.ToDateTime(TxtEndDate.Text);
        objc.Description = TxtDescription.Text;
        objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
        //objc.EmpName = LblLogdInUser.Text;
        objc.Status = TxtStatus.Text;


        int X = obj.InsertLeave(objc);
        {
            if (X >= 0)
            {
                Flag = 1;
            }
            else
            {
                Flag = 0;
            }
        }

        if (Flag == 1)
        {
            LblSuccess.Visible = true;
            LblSuccess.Text = "Data Added Successfully and Leave Application Succesfully Sent";
            DrpTypeofLeave.ClearSelection();
            TxtBeginDate.Text = "";
            TxtEndDate.Text = "";
            TxtDescription.Text = "";
            TxtNumofDays.Text = "";
            TxtStatus.Text = "";
        }
        else
        {
            LblErr.Visible = true;
            LblErr.Text = "Failed To Add Data and Send Leave Request!!!";
        }

        objc.EmpName = Convert.ToString(Session["EmpName"]);
        DataSet GrdLH = obj.GrdLeaveHistory(objc);
        DataView GrdLeaveH = new DataView();
        GrdLeaveH.Table = GrdLH.Tables[0];
        GridViewLeaveHistory.DataSource = GrdLeaveH;
        GridViewLeaveHistory.DataBind();


        MailMessage message = new MailMessage();
        message.To.Add("abcer@abc.in");
        message.Subject = "Leave Request";
        message.From = new MailAddress("abc@gmail.com");
        message.IsBodyHtml = true;

        message.Body = "<span style = font-family:Arial,font-size:10pt>";
        message.Body += "Hello <b>{Manager}</b>,<br /><br />";
        message.Body += "{LoggedInUser}has requested {TypeofLeave} for {NumofDays}"; 
        message.Body += "kindly login to the portal to accept or reject it";
        message.Body += "<br />";
        message.Body += "<br />";
        message.Body += "Thank You.<br />";
        message.Body += "</span>";
        SmtpClient smtp = new SmtpClient("");
        smtp.Send(message);
    }
4

2 回答 2

1

将您的代码更改为以下内容:[确保您将经理姓名、登录用户名、休假类型和 NoOfDays 存储在会话中或您喜欢的任何内容中,但相应地更改变量]

  message.Body += "Hello <b>"+Session["Manager"].ToString()+"</b>,<br /><br />";
  message.Body += Session["LoggedInUser"].ToString()+"has requested"+
                  Session["TypeOfLeave"].ToString()+"for "+Session["NoOfDays"].ToString()+
  mesaage.Body += "kindly login to the portal to accept or reject it";
于 2013-07-16T09:52:56.593 回答
0

与其在运行时创建 html 模板,我们可以在文本或 html 文件中定义一个带有所有占位符的模板(如 {ManagerName}、{RequestedUser})。在发送邮件时,我们可以给字典,键为 {ManagerName},{RequestedUser} 和值作为它们各自从数据库中的值。现在读取文件,然后我们可以迭代 Dictionary 的键并将键替换为模板中的值。完成这些操作后,我们创建了消息体。

于 2013-07-16T09:47:11.410 回答