public async Task <Response> SendBulkMail(BulkMailModel _bulkmailModel) { var mailClient = new SendGridClient(_configuration.GetValue <string>("ApiKey")); var mailObject = MailHelper.CreateSingleEmailToMultipleRecipients(new EmailAddress(_bulkmailModel.From, _bulkmailModel.FromName), _bulkmailModel.To, _bulkmailModel.Subject, _bulkmailModel.Body, _bulkmailModel.Body); var mailResponse = await mailClient.SendEmailAsync(mailObject); return(mailResponse); }
public static void BulkMailEmail(List <CandidateListItems> ids, string subject, string body) { var mailmodel = new BulkMailModel(); mailmodel.Subject = subject; mailmodel.Body = body; foreach (var c in ids) { var _candidate = CandidateService.CandidateList().Result.OrderBy(x => x.ID).ToList(); if (_candidate != null && _candidate.FirstOrDefault().Email != null) { mailmodel.To = _candidate.FirstOrDefault().Email; var _flagsign = BulkEmailService.BulkMails(mailmodel).Result; } } }
public async static Task <bool> BulkMails(BulkMailModel emails) { bool returnmessage = false; string BaseUri = ConfigurationManager.AppSettings["AMSBase"] + ConfigurationManager.AppSettings["AMSRoot"]; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(BaseUri); HttpResponseMessage response = client.PostAsJsonAsync("EmailService/SendBulkMail", emails).Result; if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsAsync <bool>(); returnmessage = result; } } return(returnmessage); }
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; } }