Saturday, 27 April 2013

Sending Email using Class

 Sending Email using Class


CS_SendingEmail Mail = new CS_SendingEmail();       
        Mail.UserId = ddlEmployee.SelectedValue;
                string EmailId = Mail.Get_EmailId();
                if (EmailId != null)
                {
                    Mail.From = "salikrammaurya@gmail.com";
                    Mail.To = "salikrammaurya@gmail.com";
                    Mail.Subject = "text";
                    Mail.Message = "hi how r u?";
                    Mail.MailSend();
                }
-------
 public class CS_SendingEmail
    {
         #region Property

        private System.String _From;
        private System.String _To;
        private System.String _Subject;
        private System.String _Message;
        private System.String _UserId;
        private System.Int64 _MemberId;

        public System.String From { get { return _From; } set { _From = value; } }
        public System.String To { get { return _To; } set { _To = value; } }
        public System.String Subject { get { return _Subject; } set { _Subject = value; } }
        public System.String Message { get { return _Message; } set { _Message = value; } }
        public System.String UserId { get { return _UserId; } set { _UserId = value; } }
        public System.Int64 MemberId { get { return _MemberId; } set { _MemberId = value; } }
        #endregion


 #region find emailId
        public string Get_EmailId()
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ToString());
            SqlCommand cmd = new SqlCommand("Select_EmailId", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserId", _UserId);
            try
            {
                conn.Open();
                return Convert.ToString(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return null;
        }
       
        #endregion

No comments:

Post a Comment