コード例 #1
0
 public ActionResult Contacts(bool? IsSuccess=null)
 {
     MailForm item = new MailForm();
     string lang = Request.Cookies["lang"].Value ?? "en-US";
     ViewBag.Lang = lang.Substring(0, 2);
     ViewBag.IsSuccess = IsSuccess;
     return View(item);
 }
コード例 #2
0
 public ActionResult Contacts(MailForm form, HttpPostedFileBase fileData)
 {
     if (!ModelState.IsValid)
     {
         ViewBag.IsCaptureRight = false;
         return View(form);
     }
     string lang = Request.Cookies["lang"].Value ?? "en-US";
     ViewBag.Lang = lang.Substring(0, 2);
     try
     {
         string emailFrom = "*****@*****.**";
         LocaleItemContent email = m_db.LocaleItemContent.FirstOrDefault(p => p.Language.ShortName.Equals(lang) && p.LocaleItem.Name.Equals("Email"));
         MailMessage mm = new MailMessage(emailFrom, email.Text);
         mm.Subject = form.Subject;
         mm.Body = "From: " + form.Name + "<br /><br />Email: " + form.Email + "<br /><br />" + form.Text;
         if (fileData != null)
         {
             string FileName = System.IO.Path.GetFileName(fileData.FileName);
             mm.Attachments.Add(new Attachment(fileData.InputStream, FileName));
         }
         mm.IsBodyHtml = true;
         SmtpClient smtp = new SmtpClient();
         smtp.Host = "smtp.gmail.com";
         smtp.EnableSsl = true;
         System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
         NetworkCred.UserName = emailFrom;
         NetworkCred.Password = "******";
         smtp.UseDefaultCredentials = true;
         smtp.Credentials = NetworkCred;
         smtp.Port = 587;
         smtp.Send(mm);
         return RedirectToAction("Contacts", "Home", new { IsSuccess=true });
     }
     catch
     {
         ViewBag.IsSuccess = false;
         return View(form);
     }
 }