Пример #1
0
        //
        // GET: /Email/

        public ActionResult Send(Models.SendEmailViewModel model)
        {
            try
            {
                string      sendemail = ConfigurationManager.AppSettings["sendemail"];
                string      sendpwd   = ConfigurationManager.AppSettings["sendpwd"];
                string      toemial   = ConfigurationManager.AppSettings["toemail"];
                string      smtp      = ConfigurationManager.AppSettings["smtp"];
                MailMessage message   = new MailMessage(new MailAddress(sendemail, "通知信息"), new MailAddress("*****@*****.**", "byteindex"))
                {
                    Subject    = model.name + "-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "-" + model.phone + "-" + model.email,
                    Body       = model.message,
                    IsBodyHtml = true
                };
                new SmtpClient(smtp)
                {
                    Credentials = new NetworkCredential(sendemail, sendpwd)
                }.Send(message);
                this.WriteLogs(string.Format("成功发送邮件:from:{0}->to:{1}", sendemail, "*****@*****.**"));
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public ActionResult Send_Email(Models.SendEmailViewModel model, HttpPostedFileBase postedFile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    String toEmail  = model.ToEmail;
                    String subject  = model.Subject;
                    String contents = model.Contents;

                    string serverPath = Server.MapPath("~/Uploads/");
                    if (!Directory.Exists(serverPath))
                    {
                        Directory.CreateDirectory(serverPath);
                    }
                    string path = "";

                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        string fileName = Path.GetFileName(postedFile.FileName);
                        path = serverPath + fileName;
                        postedFile.SaveAs(serverPath + fileName);
                    }

                    Utils.EmailSender es = new Utils.EmailSender();
                    es.Send(toEmail, subject, contents, path, postedFile);

                    ViewBag.Result = "Email has been send.";

                    ModelState.Clear();

                    return(View(new Models.SendEmailViewModel()));
                }
                catch
                {
                    return(View());
                }
            }

            return(View());
        }
Пример #3
0
        //
        // GET: /Email/

        public ActionResult Send(Models.SendEmailViewModel model)
        {
            try
            {
                string      sendemail   = ConfigurationManager.AppSettings["sendemail"];
                string      sendpwd     = ConfigurationManager.AppSettings["sendpwd"];
                string      toemial     = ConfigurationManager.AppSettings["toemail"];
                string      smtp        = ConfigurationManager.AppSettings["smtp"];
                MailMessage mailMessage = new MailMessage(new MailAddress(sendemail, "比特城邦网络科技有限公司-邮件通知"), new MailAddress(toemial, "老板"));
                mailMessage.Subject    = string.Format("联系我们-{0}-{1}-{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), model.name, model.email);
                mailMessage.Body       = model.message;
                mailMessage.IsBodyHtml = true;

                SmtpClient client = new SmtpClient(smtp);
                client.Credentials = new NetworkCredential(sendemail, sendpwd);
                client.Send(mailMessage);
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }