Beispiel #1
0
        public IndexEmailModel GetAll()
        {
            IndexEmailModel model = new IndexEmailModel();

            model.lstEmails     = _iEmailRepository.GetAllEmails().UseAsDataSource(Mapper.Configuration).For <EmailViewModel>().ToList();
            model.lstSentEmails = _iEmailRepository.GetAllSentEmails().UseAsDataSource(Mapper.Configuration).For <SentEmailViewModel>().ToList();
            model.SentEmail     = new SentEmailViewModel();
            model.Email         = new EmailViewModel();
            return(model);
        }
Beispiel #2
0
        public IEnumerable <Email> GetAllEmails()
        {
            var allEmails = _emailRepository.GetAllEmails();
            var emails    = allEmails as IList <Data.Models.Email> ?? allEmails.ToList();

            if (!emails.Any())
            {
                return(null);
            }

            return(from email in emails
                   select new Email
            {
                Id = email.Id,
                Subject = email.Subject,
                From = email.From,
                To = email.To,
                BodyHtml = email.BodyHtml
            });
        }
Beispiel #3
0
        public async Task <IActionResult> GetEmails([FromQuery(Name = "pageNumber")] int PageNumber, [FromQuery(Name = "pageSize")] int PageSize)
        {
            try
            {
                if (PageNumber <= 0)
                {
                    return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "Page number not found!"));
                }
                else if (PageSize <= 0)
                {
                    return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "Page size not found!"));
                }
                else
                {
                    PagedList <EmailDTO> items = await _emailRepo.GetAllEmails(PageNumber, PageSize);

                    if (items != null)
                    {
                        var result = new
                        {
                            items.TotalCount,
                            items.PageSize,
                            items.CurrentPage,
                            items.TotalPages,
                            items.HasNext,
                            items.HasPrevious,
                            items
                        };
                        return(Ok(result));
                    }
                    else
                    {
                        return(NoContent());
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public async Task <IEnumerable <Email> > Handle(GetAllEmailsQuery request, CancellationToken cancellationToken)
 {
     return(await _repository.GetAllEmails(cancellationToken));
 }
        public async Task <Response <IEnumerable <EmailDto> > > Handle(GetAllEmailsQuery request, CancellationToken cancellationToken)
        {
            IEnumerable <EmailEntity> emails = emailRepo.GetAllEmails();

            return(Response.Ok <IEnumerable <EmailDto> >(emails.Select(x => EmailDto.Make(x))));
        }
Beispiel #6
0
        public ViewResult Index()
        {
            var model = emailRepository.GetAllEmails();

            return(View(model));
        }
Beispiel #7
0
        public IActionResult SendMailAsync(BulkMailModel model)
        {
            try
            {
                model.Email_list = _email_repo.GetAllEmails().ToList <EmailModel>();

                MimeMessage message = new MimeMessage();

                // sender info
                MailboxAddress from = new MailboxAddress("Admin", "*****@*****.**");
                message.From.Add(from);
                message.Subject = ".NET Core Esender Mail";

                BodyBuilder bodyBuilder = new BodyBuilder();
                bodyBuilder.HtmlBody = model.Mail_text;
                message.Body         = bodyBuilder.ToMessageBody();

                foreach (var mail_addrs in model.Email_list)
                {
                    MailboxAddress to = new MailboxAddress(mail_addrs.FirstName
                                                           + " "
                                                           + mail_addrs.LastName,
                                                           mail_addrs.Email);
                    message.To.Add(to);
                }

                #region OAuth2 but gives a uri_mismatch_error (commented)

                /*
                 * const string GMailAccount = "*****@*****.**"; //User.Identity.Name
                 *
                 * var clientSecrets = new ClientSecrets
                 * {
                 *  ClientId = "993637890339-f3rpvl6rbl3raa7usd9301gvsmv49gcq.apps.googleusercontent.com",
                 *  ClientSecret = "RyjONIbfVo18iADMGdusLg_X"
                 * };
                 *
                 * var codeFlow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                 * {
                 *  // Cache tokens in ~/.local/share/google-filedatastore/CredentialCacheFolder on Linux/Mac
                 *  DataStore = new FileDataStore("CredentialCacheFolder", false),
                 *  Scopes = new[] { "https://mail.google.com/" },
                 *  ClientSecrets = clientSecrets
                 * });
                 *
                 * var codeReceiver = new LocalServerCodeReceiver();
                 * var authCode = new AuthorizationCodeInstalledApp(codeFlow, codeReceiver);
                 * var credential = await authCode.AuthorizeAsync(GMailAccount, CancellationToken.None);
                 *
                 * if (authCode.ShouldRequestAuthorizationCode(credential.Token))
                 *  await credential.RefreshTokenAsync(CancellationToken.None);
                 *
                 * var oauth2 = new SaslMechanismOAuth2(credential.UserId, credential.Token.AccessToken);
                 *
                 * using (var imap_client = new ImapClient())
                 * {
                 *  await imap_client.ConnectAsync("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect);
                 *  await imap_client.AuthenticateAsync(oauth2);
                 *  await imap_client.DisconnectAsync(true);
                 * }
                 */
                #endregion

                SmtpClient client = new SmtpClient();
                client.Connect("smtp.gmail.com", 465, true);
                client.Authenticate("*****@*****.**", "ldboymuunjenvlqy");

                client.Send(message);
                client.Disconnect(true);
                client.Dispose();

                return(RedirectToActionPermanent("Index", "Home"));
            }
            catch (Exception e)
            {
                throw e;
            }
        }