在电子邮件中发送用户

时间:2013-11-28 17:25:31

标签: c# asp.net email

我在用户各自的电子邮件地址发送邮件,当他收到邮件时,他会看到像这样的邮件信息

docname = abc status = reject

现在我还要添加用户名,并希望显示批准其文档的人

我在会话中保存用户名,然后当任何用户登录时,他/她的名字在右上方的短号中可见,我在会话中保存此名称

 Session["Login2"] = txt_username.Value;

现在假设主管通过他们的帐户登录并批准任何文件并发送邮件,然后当用户收到邮件时,他将能够看到这样的邮件

  docname= abc
 status=reject
 username  = john

电子邮件代码

             string DocName = ((Label)Repeater2.Items[i].FindControl("DocName")).Text;
                  string emailId = 
                ((Label)Repeater2.Items[i].FindControl("YourEamil")).Text;
                  DropDownList dropdownvalue = 
               ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));

                  string docname = String.Empty;
                  string emailID = String.Empty;
                  string dropdownvalues = String.Empty;




                  if (DocName.ToString() != "")
                  {
                      docname = DocName.ToString();
                  }
                  else
                  {
                      docname = "Unavailable";
                  }
                  if (emailId.ToString() != "")
                  {
                      emailID = emailId.ToString();
                  }
                  else
                  {
                      emailID = "Unavailable";
                  }

                  if (dropdownvalue.SelectedItem.ToString() != "")
                  {
                      dropdownvalues = dropdownvalue.SelectedItem.ToString();
                  }
                  else
                  {
                      dropdownvalues = "Unavailable";
                  }


                  SendEmailUsingGmail(DocName, emailId, dropdownvalues);


                  cmd.ExecuteNonQuery();




              }

          }
          else
          {
              Supvisor.Text = "Error";
          }
          if (mySQLconnection.State == ConnectionState.Open)
          {
              mySQLconnection.Close();
          }

                }
    private void SendEmailUsingGmail(string DocName, string emailId, string 
   dropdownvalue)
    {
        try
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Credentials = new NetworkCredential("ketyycute@gmail.com", "123213");
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            MailMessage message = new MailMessage();
            message.From = new MailAddress("ketyycut@gmail.com");
            message.To.Add(emailId);
            //message.To.Add(New MailAddress(toEmailAddress));
            message.Subject = "Document Managment System=" + "DropDownList4" + dropdownvalue;
            message.Body = "DocName=" + DocName + " DropDownList4=" + dropdownvalue;

            smtp.Send(message);
        }
        catch (Exception ex)
        {
            Response.Write("Error occured: " + ex.Message.ToString());
        }
    }

我是怎么做到的

1 个答案:

答案 0 :(得分:0)

您拥有在会话中批准该用户的用户名。 要检索这个:

string approver;
if (Session["Login2"] != null)
{
    approver = Session["Login2"].ToString();
}

如果您还希望电子邮件中批准文档的创建者/所有者的名称超过您在创建文档时所需的名称。