示例#1
0
        public JsonResult Send_mail(string email_To)
        {
            DataAccessLeyer.DAL.BILLINSERT_DAL bcls = new DataAccessLeyer.DAL.BILLINSERT_DAL();
            string strqry1 = "select * from user_name where emailid = '" + email_To + "'";
            System.Data.DataTable dt1 = bcls.settingval(strqry1);
            if (dt1.Rows.Count == 0)
            {
                return Json("Mail Id Not Exist", JsonRequestBehavior.AllowGet);
            }

            string strqry = "select * from MAILSETTINGTABLE where branchcode = '" + dt1.Rows[0]["branchcode"].ToString() + "'";
            System.Data.DataTable dt = bcls.settingval(strqry);

            string smtpAddress = dt.Rows[0]["SMTP_ADDRESS"].ToString();// "smtp.gmail.com";
            int portNumber = Convert.ToInt32(dt.Rows[0]["PORT_NUMBER"].ToString()); //  587;
            bool enableSSL = true;

            string emailFrom = dt.Rows[0]["EMAIL_FROM"].ToString(); // "*****@*****.**";
            string password = dt.Rows[0]["PASSWORD"].ToString(); // "sansoft@123";
            string emailTo = email_To; //  "*****@*****.**";
            string subject =  "Hello";
            string body = "Your  Password is : "+ dt1.Rows[0]["Password"].ToString(); // "Hello, I'm just writing this to say Hi!";

            using (System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage())
            {
                mail.From = new System.Net.Mail.MailAddress(emailFrom);
                mail.To.Add(emailTo);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                // Can set to false, if you are sending pure text.
               // mail.Attachments.Add(new System.Net.Mail.Attachment(""));
                //  mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));

                using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new System.Net.NetworkCredential(emailFrom, password);
                    smtp.EnableSsl = enableSSL;
                    smtp.Send(mail);
                }
            }

            return Json("Mail Send Successfully", JsonRequestBehavior.AllowGet);
        }
        public JsonResult Send_mail(string email_To, string subject_b, string body_b, string attach_ment, string Adminem, string Exuctem)
        {
            DataAccessLeyer.DAL.BILLINSERT_DAL bcls = new DataAccessLeyer.DAL.BILLINSERT_DAL();

            string strqry = "select * from MAILSETTINGTABLE where branchcode = '"+branchcode+"'";
            DataTable dt =   bcls.settingval(strqry);

            string smtpAddress = dt.Rows[0]["SMTP_ADDRESS"].ToString() ;// "smtp.gmail.com";
            int portNumber = Convert.ToInt32(dt.Rows[0]["PORT_NUMBER"].ToString()); //  587;
            bool enableSSL = true;

            string emailFrom = dt.Rows[0]["EMAIL_FROM"].ToString(); // "*****@*****.**";
            string password = dt.Rows[0]["PASSWORD"].ToString(); // "sansoft@123";
            string emailTo = email_To; // "*****@*****.**";
            string subject = subject_b; // "Hello";
            string body = body_b; // "Hello, I'm just writing this to say Hi!";

            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom);
                mail.To.Add(emailTo);
                mail.To.Add(Adminem);
                mail.To.Add(Exuctem);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                // Can set to false, if you are sending pure text.
                mail.Attachments.Add(new Attachment(Server.MapPath(attach_ment)));
              //  mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));

                using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl = enableSSL;
                    smtp.Send(mail);
                }
            }

            return Json("Mail Send Successfully",JsonRequestBehavior.AllowGet);
        }