Exemplo n.º 1
0
        public async Task <DbResult> Send_Email_With_Attachement(string name, string email, string subject, string message, string file)
        {
            var result = new DbResult {
                Success = true
            };

            try
            {
                using (var mail = new MailMessage())
                {
                    mail.Body       = message;
                    mail.IsBodyHtml = true;
                    mail.Subject    = subject;
                    mail.Priority   = MailPriority.High;
                    mail.To.Add(new MailAddress(email, name));
                    mail.From = new MailAddress(_options.From, _options.Display_Name);
                    mail.Attachments.Add(new Attachment(file));
                    using (var client = GetSmtpClient())
                    {
                        await client.SendMailAsync(mail);
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false; result.Message = ex.Message;
                string info = string.Format("SendEmailAsync: Name:- {0}, Email:- {1}, Subject:- {2}", name, email, subject);
                ExceptionGateway.AddException(new ExceptionLog(ex, info));
            }
            return(await Task.FromResult(result));
        }
Exemplo n.º 2
0
        public string GetMailTemplate(dynamic obj, string template)
        {
            string htmlBody = string.Empty;

            try
            {
                Email.DefaultRenderer = new RazorRenderer();
                var template_path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "email-template", template);
                var testEmail     = Email.From(_options.From).UsingTemplateFromFile(template_path, obj);
                htmlBody = testEmail.Data.Body;
            }
            catch (Exception ex)
            {
                string messgae = ex.Message;
                string info    = string.Format("GetMailTemplate: Template:- {0}", template);
                ExceptionGateway.AddException(new ExceptionLog(ex, info));
            }
            return(htmlBody);
        }