Beispiel #1
0
        public async Task <bool> SendOffer(Offer offer)
        {
            // get supplier email form identity server by (offer.SuplierId)

            var supplierEmail = "*****@*****.**";// test data
            var emailModel    = new Models.EmailModel
            {
                To = new List <string> {
                    supplierEmail
                },
                Subject = configuration.GetSection("Email:SendOffer:subject").Value,
                Body    = string.Format(
                    configuration.GetSection("Email:SendOffer:body").Value,
                    offer.OfferId)
            };

            // get supplier mobile number form identity server by (offer.SuplierId)
            var supplierMobile = "0511111111";// test data


            var smsModel = new Models.SmsModel
            {
                To = new List <string> {
                    supplierMobile
                },
                Body = string.Format(
                    configuration.GetSection("SMS:SendOffer").Value,
                    offer.OfferId)
            };
            var task1 = await _notification.SendEmail(emailModel);

            var task2 = await _notification.SendSms(smsModel);

            return(task1 == true && task1 == true);
        }
Beispiel #2
0
        public IActionResult SendMail([FromBody] Models.EmailModel model)
        {
            var es = new Services.EmailService();

            es.Send(model.To, model.Subject, model.Body);
            return(Ok());
        }
Beispiel #3
0
        public ActionResult SendEmail(Models.EmailModel model)
        {
            using (System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(model.Email, model.To))
            {
                mm.Subject = model.Subject;
                mm.Body    = model.Body;
                if (model.Attachment.ContentLength > 0)
                {
                    string fileName = Path.GetFileName(model.Attachment.FileName);
                    mm.Attachments.Add(new Attachment(model.Attachment.InputStream, fileName));
                }
                mm.IsBodyHtml = false;
                using (SmtpClient smtp = new SmtpClient())
                {
                    smtp.Host      = "smtp.gmail.com";
                    smtp.EnableSsl = true;
                    NetworkCredential NetworkCred = new NetworkCredential(model.Email, model.Password);
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials           = NetworkCred;
                    smtp.Port = 587;
                    smtp.Send(mm);
                    ViewBag.Message = "Email sent.";
                }
            }

            return(View());
        }
Beispiel #4
0
        public override void SendEmail(Models.EmailModel email)
        {
            //TODO: Implement the email send request to mail gun
            using (var client = new HttpClient())
            {
            }

            throw new NotImplementedException();
        }
        public ActionResult Contact()
        {
            ViewBag.ReturnUrl     = Request.Url.LocalPath;
            ViewBag.StatusMessage = "";
            ViewBag.Message       = "If you wish to contact me for some reason...";
            EmailModel email = new Models.EmailModel();

            return(View());
        }
Beispiel #6
0
 public static async Task ComposeEmailAsync(Models.EmailModel email)
 {
     try
     {
         var senderEmail = $"{email.FromEmail}<{ConfiguredEmail}>";
         var mailMsg     = new MailMessage(senderEmail, ConfiguredEmail)
         {
             Subject    = email.Subject,
             Body       = $"<strong>{email.FromName} has sent you the following message</strong><hr/r> {email.Body}",
             IsBodyHtml = true
         };
         var svc = new EmailService();
         await svc.SendAsync(mailMsg);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         await Task.FromResult(0);
     }
 }
Beispiel #7
0
        public async Task <ActionResult> Contact(Models.EmailModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var body = "<p>Email From: <bold>{0}</bold>({1})</p><p>Message:</p><p>{2}</p>";
                    var from = "MyPortfolio<*****@*****.**>";

                    var email = new MailMessage(from, ConfigurationManager.AppSettings["emailto"])
                    {
                        Subject    = "Portfolio Contact Email",
                        Body       = string.Format(body, model.FromName, model.FromEmail, model.Body),
                        IsBodyHtml = true
                    };

                    var svc = new Models.EmailHelper(); await svc.SendAsync(email);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); await Task.FromResult(0); }
            }
            return(View(model));
        }
Beispiel #8
0
        public PartialViewResult Recovery(Models.EmailModel payload)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView(toastViewPath, new MessageDisplayModel
                {
                    Title = "Email not sent.",
                    Color = "danger",
                    Message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors))
                }));
            }

            var EFUser = _auth.GetCredentials(payload.Email);

            if (EFUser == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(PartialView(toastViewPath, new MessageDisplayModel
                {
                    Title = "Email not sent.",
                    Color = "danger",
                    Message = "Email not registered."
                }));
            }

            try
            {
                // get new password recovery hash created to user
                var passwordRecoveryHash = _auth.ProvideLinkToRecovery(EFUser);
                // current root url to complete link
                var rootUrl = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
                // setup view model to fill email
                var passwordRecoveryModel = new PasswordRecoveryEmailModel
                {
                    RecipientEmail       = EFUser.Email,
                    RecipientDisplayName = EFUser.Name,
                    RecoveryLink         = $"{rootUrl}/Login/PasswordRecovery?email={EFUser.Email}&verifier={passwordRecoveryHash.HashCode}",
                    ExpireDate           = passwordRecoveryHash.ExpirationDate.Value,
                    Site = rootUrl
                };
                // render the view as string to send via SMTP
                var emailContentHtml = StringRenderer.RenderView(passwordRecoveryViewPath, passwordRecoveryModel, false);

                _email.Send(emailContentHtml, passwordRecoveryModel);
            }
            catch (Exception e)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(PartialView(toastViewPath, new MessageDisplayModel
                {
                    Title = "Email not sent.",
                    Color = "danger",
                    Message = e.Message
                }));
            }

            Response.StatusCode = (int)HttpStatusCode.OK;
            return(PartialView(toastViewPath, new MessageDisplayModel
            {
                Title = "Email sent.",
                Color = "success",
                Message = "Por favor, verifique sua caixa de e-mail."
            }));
        }
        public ActionResult Contact()
        {
            Models.EmailModel model = new Models.EmailModel();

            return(View(model));
        }
Beispiel #10
0
 public abstract void SendEmail(Models.EmailModel email);