Esempio n. 1
0
        public ViewResult ShareFilePaymentDocView(Guid paymentDocId)
        {
            var findPaymentDocument = _paymentDocRepository.GetPaymentDocumentById(paymentDocId);

            SharePaymentViewModel sentToMail = new SharePaymentViewModel
            {
                PaymentDocument = findPaymentDocument
            };

            return(View("ShareFilePaymentDocView", sentToMail));
        }
Esempio n. 2
0
        public ActionResult ShareFilePaymentDoc(SharePaymentViewModel sentToMail)
        {
            var findPaymentDocument = _paymentDocRepository.GetPaymentDocumentById(sentToMail.PaymentDocument.PaymentDocId);

            var path = Path.Combine(Server.MapPath("~/App_Data/PaymentDoc/"), findPaymentDocument.PaymentDocId + findPaymentDocument.Extension);

            if (ModelState.IsValid)
            {
                string from = "*****@*****.**"; //example:- [email protected]

                using (MailMessage mail = new MailMessage(from, sentToMail.To))
                {
                    mail.Subject = sentToMail.Subject;
                    mail.Body    = sentToMail.Body;
                    if (true)
                    {
                        string fileName = sentToMail.PaymentDocument.PaymentFileName;
                        mail.Attachments.Add(new Attachment(path, fileName));
                    }
                    mail.IsBodyHtml = false;
                    SmtpClient smtp = new SmtpClient
                    {
                        Host      = "smtp.gmail.com",
                        EnableSsl = true
                    };
                    NetworkCredential networkCredential = new NetworkCredential(from, "boatboat57150");
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials           = networkCredential;
                    smtp.Port = 587;
                    smtp.Send(mail);
                    ViewBag.Message = "Sent";

                    return(RedirectToAction("ListAllPaymentDocs", "PaymentDoc"));
                }
            }

            return(View("ShareFilePaymentDocView", sentToMail));
        }