public ActionResult SendIntroMail(int companyId, string subject, string body, string email) { if (string.IsNullOrEmpty(email)) { email = Request.Form["Company.Email"]; } if (!string.IsNullOrEmpty(Request.Form["Send"])) { IEmailService service = new GoogleEmailService(); #if DEBUG service = new SendGridEmailService(); #endif service.SendIntroMail(companyId, subject, body, email); TempData["Message"] = "Email Sent"; if (Request?.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.OriginalString)); } return(RedirectToAction("Edit", "Companies", new { id = companyId, message = "Email Sent" })); } ScheduledEmailRepository emailRepository = new ScheduledEmailRepository(); emailRepository.Add(companyId, subject, body, email); TempData["Message"] = "Email Scheduled"; if (Request?.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.OriginalString)); } return(RedirectToAction("Edit", "Companies", new { id = companyId, message = "Email Scheduled" })); }
//[ValidateAntiForgeryToken] public async Task <ActionResult> ClaimCompanyReferal([Bind(Exclude = nameof(ClaimingViewModel.IsAgreedWithTerms))] ClaimingViewModel model, string partialName) { ModelState.Remove(nameof(ClaimingViewModel.IsAgreedWithTerms)); if (ModelState.IsValid) { if (IsValidDomain(model.Company.Email, model.Email)) { var bodyHtml = System.IO.File.ReadAllText(Server.MapPath("/Templates/ClaimCompanyReferal.html")); var bodyBuilder = new StringBuilder(bodyHtml); var signupLink = $"{Request.Url.Scheme}://{Request.Url.Host}:{Request.Url.Port}{Url.Action(nameof(Details), "Business", new { id = model.Company.Id })}"; bodyBuilder.Replace("@@CompanyName@@", model.Company.Name); bodyBuilder.Replace("@@Address@@", signupLink); bodyBuilder.Replace("@@Name@@", model.Name); var emailService = new GoogleEmailService(model.Email, "Claim company", model.Email, bodyBuilder.ToString(), true, false); emailService.SendMail(); } else { await _registrationRepository.AddRegistrationRequest(new ClaimRequest { CompanyId = model.Company.Id, Email = model.Email, RequestTime = DateTime.Now }); } ViewBag.SuccessMessage = ResourceString.Instance.RegistrationSuccessfulMessage; } return(PartialView(partialName, model)); }
static void Main(string[] args) { UserCredential credential; using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Google Sheets API service. var service = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); var googleSpreadSheet = new GoogleSpreadsheet("1eKY_4hPVlsBRcHkYfTHJxMOXT_nb4NlAy7kOaBOaXuk", service); var orders = googleSpreadSheet.GetCurrentOrders(); IMailService mailService = new GoogleEmailService(); // Foodie spreadsheet: }
private void SendEmail(string notificationEmailBody, string emailToSend) { IEmailService emailService = new GoogleEmailService(emailToSend, "You have new notifications", string.Empty, notificationEmailBody, true, false); #if DEBUG emailService = new SendGridEmailService(emailToSend, "Test subject", string.Empty, notificationEmailBody, true, true); #endif emailService.SendMail(); }
public async Task <ActionResult> Approve(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ClaimRequest request = db.ClaimRequests.Find(id); if (request == null) { return(HttpNotFound()); } var company = _companyRepository.GetCompany(request.CompanyId); var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var newUser = new ApplicationUser { UserName = request.Email, Email = request.Email }; var password = Guid.NewGuid().ToString().Substring(0, 8) + "!1jK"; var oldUser = await userManager.FindByNameAsync(newUser.UserName); var resultOfDelete = await userManager.DeleteAsync(oldUser); if (resultOfDelete.Succeeded) { var result = await userManager.CreateAsync(newUser, password); if (result.Succeeded) { await userManager.AddToRoleAsync(newUser.Id, Constants.CompanyRole); newUser.CompanyId = company.Id; await userManager.UpdateAsync(newUser); var subject = "Company registered"; var body = "Your company is registered. Your account password is " + password; var emailService = new GoogleEmailService( company.Email, subject, company.Name, body, true, false ); emailService.SendMail(); } } request.ClaimStatus = ClaimStatus.Approved; request.ApproveTime = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult TestGbdrm() { var email1 = new GoogleEmailService("*****@*****.**", "Hello", "Viktor", "Hello, V. How are you?", true, false); var res1 = email1.SendMail(); var email2 = new GoogleEmailService("*****@*****.**", "Hello", "Viktor", "Hello, V2. How are you?", true, true); var res2 = email2.SendMail(); return(Content($"{res1} **** {res2}")); }
public ActionResult TestEmail() { IEmailService service = new GoogleEmailService("*****@*****.**", "test", "test", "test", false, false); #if DEBUG service = new SendGridEmailService("*****@*****.**", "test", "test", "test", false, false); #endif return(Content(service.SendMail())); }
public async Task <ActionResult> RunScheduled() { await RunNotificationEmails(); lock (obj) { DatabaseLogging logging = new DatabaseLogging(); DateTime now = DateTimeHelper.GetCurrentDateTimeByTimeZone(Constants.CurrentTimeZoneId); logging.Add($"Run Scheduled emails. Today is {now.DayOfWeek}. Time: {now.Hour}:{now.Minute}. Full: {now}"); if (now.DayOfWeek == DayOfWeek.Saturday || now.DayOfWeek == DayOfWeek.Sunday) { logging.Add("We don't send emails today " + now.DayOfWeek + " " + now); return(Content("We don't send emails today " + now.DayOfWeek + " " + now)); } if (now.Hour != 9) { logging.Add("time is not correct " + now.Hour + " Full: " + now); return(Content("time is not correct " + now.Hour + " Full: " + now)); } ScheduledEmailRepository emailRepository = new ScheduledEmailRepository(); IEmailService emailService = new GoogleEmailService(); #if DEBUG emailService = new SendGridEmailService(); #endif var scheduled = emailRepository.GetScheduled().ToList(); logging.Add($"Schedule time is fine. Got {scheduled.Count} emails to sent"); foreach (var email in scheduled) { try { emailService.SendIntroMail(email.CompanyId, email.Subject, email.Body, email.Email); emailRepository.UpdateStatus(email.Id, EmailStatus.Sent); logging.Add($"Email {email.Id} is sent"); } catch (Exception e) { emailRepository.UpdateStatus(email.Id, EmailStatus.Failed); logging.Add($"Email {email.Id} is failed. Error: {e.Message}"); } } logging.Add($"***Scheduled emails are done***"); } return(Content("OK")); }
/// <summary> /// Send email with new password /// </summary> private void SendEmail(ClaimingViewModel model, string password) { // send an email var bodyHtml = System.IO.File.ReadAllText(Server.MapPath("/Templates/ClaimCompany.html")); var bodyBuilder = new StringBuilder(bodyHtml); var loginLink = $"{Request.Url.Scheme}://{Request.Url.Host}:{Request.Url.Port}/{Url.Action("Details", "Business", new { id = model.Company.Id })}"; bodyBuilder.Replace("@@CompanyName@@", model.Company.Name); bodyBuilder.Replace("@@Address@@", loginLink); bodyBuilder.Replace("@@Password@@", password); var emailService = new GoogleEmailService(model.Email, "Claim company", model.Email, bodyBuilder.ToString(), true, false); emailService.SendMail(); }
public static void DependencyInjection() { ////Dependency Injection /// //Constructor injection example var googleEmailService = new GoogleEmailService(); var userLogicConstructorInjection = new UserLogicConstructorInjection(googleEmailService); //Setter injection OutlookEmailService outlookEmailService = new OutlookEmailService(); var userLogicSetter = new UserLogicSetterInjection() { EmailService = outlookEmailService }; //Method injection OutlookEmailService outlookEmailService2 = new OutlookEmailService(); var userLogicMethod = new UserLogicMethodInjection(); userLogicMethod.Register("*****@*****.**", "Test12345", outlookEmailService); }
public UserLogicBadExample1() { _authService = new GoogleOAuthService(); _emailService = new GoogleEmailService(); }