public async Task <Response> Execute(string emailAddress) { var user = await _userService.FindByEmailAsync(emailAddress); if (user == null) { System.Net.HttpStatusCode statusCode = System.Net.HttpStatusCode.Unauthorized; return(new Response(statusCode, null, null)); } var token = _tokenHandler.CreatePasswordResetToken(user); var apiKey = Environment.GetEnvironmentVariable("Testology_sendgrid_key"); var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "Ashley"); // var from = new EmailAddress("*****@*****.**", "Ashley"); var to = new EmailAddress(emailAddress, "usuario de Testology"); var templateData = new MailData(); var frontendDomain = _configuration.GetValue <string>("FrontendDomain"); templateData.PasswordChangeUrl = frontendDomain + "/sesion/nuevo-pass/" + token; var msg = MailHelper.CreateSingleTemplateEmail(from, to, "d-4bbc02bd9fd743bda97189fa9f4161f7", templateData); var response = await client.SendEmailAsync(msg); return(response); }
public async Task <IActionResult> AcceptUser(Guid userId, bool accept) { if (accept) { await this.userService.AssignRoleToUser(Roles.User, userId); var apiKey = "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"; var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "Zajonc"); var to = new EmailAddress(this.userService.GetMail(userId), "Example User"); var dynamicTemplateData = new Dictionary <string, string> { { "first_name", "<p>this is some html</p>" }, { "last_name", "<div>l23456</div>" }, { "Sender_Name", "<div>Sender_Name</div>" }, }; var msg = MailHelper.CreateSingleTemplateEmail(from, to, "d-439559e2079846e0b3214f6186b6f019", dynamicTemplateData); _ = await client.SendEmailAsync(msg); } else { await this.userService.UnassignRoleToUser(Roles.User, userId); } return(this.NoContent()); }
/// <summary> /// Sends a notification email to the teacher letting them know that a student has created an extension request /// </summary> /// <param name="teacher"></param> /// <param name="student"></param> /// <param name="extensionRequest"></param> public async void SendExtensionCreatedEmailToTeacher(ApplicationUser teacher, ApplicationUser student, ExtensionRequest extensionRequest) { var dynamicTemplateData = new { Recipient = new { Name = teacher.Firstname }, Extension = new { Title = extensionRequest.Title, Description = extensionRequest.Description, AttachmentCount = extensionRequest.UploadedDocuments?.Count, CreatedBy = extensionRequest.StudentCreatedBy.Fullname, LinkUrl = $"{_urlDomain}/Tutor/ReviewExtension?id={extensionRequest.Id}", } }; var to = new EmailAddress(teacher.Email, teacher.Fullname); var msg = MailHelper.CreateSingleTemplateEmail( _fromEmailAddress, to, _extensionCreatedTeacherNotificationTemplateId, dynamicTemplateData); await _sendGridClient.SendEmailAsync(msg); var notification = new Notification { UserId = extensionRequest.TutorAssignedTo.Id, Text = $"{extensionRequest.StudentCreatedBy.Fullname} has created a new extension {extensionRequest.Title}" }; _notificationRepository.InsertNotification(notification); }
public async void SendInboundEmailExtensionCreated(string toEmail, string toName, ExtensionRequest extensionRequest) { var dynamicTemplateData = new { Recipient = new { Name = toName }, Extension = new { Id = extensionRequest.Id, Title = extensionRequest.Title, Description = extensionRequest.Description, TeacherAssignedTo = extensionRequest.TutorAssignedTo.Fullname, AttachmentCount = extensionRequest.UploadedDocuments?.Count, LinkUrl = $"{_urlDomain}/Student/Applications" } }; var to = new EmailAddress(toEmail, toName); var msg = MailHelper.CreateSingleTemplateEmail( _fromEmailAddress, to, _extensionRequestCreatedTemplateId, dynamicTemplateData); await _sendGridClient.SendEmailAsync(msg); }
public async Task <bool> SendContactThankYou(ContactForm contactForm) { try { var client = new SendGridClient(_configuration.ApiKey); var from = new EmailAddress(_configuration.From); var to = new EmailAddress(contactForm.EmailAddress); var msg = MailHelper.CreateSingleTemplateEmail(from, to, CONTACT_THANK_YOU_TEMPLATE, new { name = HttpUtility.HtmlEncode(contactForm.Name), howcanihelp = HttpUtility.HtmlEncode(contactForm.HowCanIHelp) }); if (!contactForm.EmailAddress.ToLower().Equals(_configuration.From.ToLower())) { msg.AddBcc(new EmailAddress(_configuration.From)); } var response = await client.SendEmailAsync(msg); return(response?.StatusCode == HttpStatusCode.Accepted); } catch { } return(false); }
public async Task <ActionResult <dynamic> > Post( [FromBody] Email model ) { Console.WriteLine(model); var apiKey = "KEY SENDGRID"; var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "Wallace Brito"); var to = new EmailAddress(model.Emails, model.Template.Name); var templateId = model.TemplateId; var dynamicTemplateData = new ExampleTemplateData { Subject = model.Template.Subject, Name = model.Template.Name, Valor = model.Template.Valor }; var msg = MailHelper.CreateSingleTemplateEmail( from, to, templateId, dynamicTemplateData ); var response = await client.SendEmailAsync(msg); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Headers.ToString()); return(model); }
static public async Task <Result> SendEmail(string email, string link, EmailProviderSettings settings, string settingMessageId) { try { var client = new SendGridClient(settings.SendGridApiKey); var from = new EmailAddress(settings.SenderEmail, "PMAsystent"); var to = new EmailAddress(email, "PMAsystent"); var dynamicTemplateData = new Dictionary <string, string> { { "url", link }, }; var msg = MailHelper.CreateSingleTemplateEmail(from, to, settingMessageId, dynamicTemplateData); var response = await client.SendEmailAsync(msg); if (response.IsSuccessStatusCode) { return(Result.Success()); } return(Result.Failure(new List <string> { "Błąd serwisu mailowego: " + response.StatusCode.ToString() })); } catch (Exception e) { return(Result.Failure(new List <string> { e.Message })); } }
public async Task <ActionResult <Dictionary <string, bool> > > Partner(JObject payload) { var data = JsonConvert.DeserializeObject <Partner>(payload.ToString()); var email = data.Email; var apiKey = configuration.GetSection("SENDGRID_API_KEY").Value; var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "Project CORA"); var to = new EmailAddress(email); // welcome email to partner var templateId1 = "d-b3a547bacdf5498294cf0064dde9200f"; var msg1 = MailHelper.CreateSingleTemplateEmail(from, to, templateId1, data); //eamail data to cora team var templateId2 = "d-942b1b931faf409f8589b611e57e64e6"; var response = await client.SendEmailAsync(msg1); var msg2 = MailHelper.CreateSingleTemplateEmail(from, from, templateId2, data); return(new Dictionary <string, bool>() { { "partnered", (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.Accepted) } }); }
public async Task SendInvitationMessageAsync(CarReservationConfirmationMailTemplate carReservationConfirmationMailTemplate) { var emailMessage = MailHelper.CreateSingleTemplateEmail( new EmailAddress(_mailDeliveryServiceConfiguration.FromEmail), new EmailAddress(carReservationConfirmationMailTemplate.CustomerEmail), _mailDeliveryServiceConfiguration.CarReservationConfirmationTemplateId, new { customerName = carReservationConfirmationMailTemplate.CustomerName, carBrand = carReservationConfirmationMailTemplate.CarBrand, carModel = carReservationConfirmationMailTemplate.CarModel, carImageUrl = carReservationConfirmationMailTemplate.CarImageUrl, fromDate = carReservationConfirmationMailTemplate.FromDate, toDate = carReservationConfirmationMailTemplate.ToDate }); var response = await _sendGridClient.SendEmailAsync(emailMessage); if (response.StatusCode != HttpStatusCode.Accepted) { var responseContent = await response.Body.ReadAsStringAsync(); _logger.LogError($"SendGrid service returned status code {response.StatusCode} with response: {responseContent}"); } }
public async Task SendTemplateAsync(TemplateEmail email) { var from = new EmailAddress(email.SenderEmailAddress, email.SenderName); var to = new EmailAddress(email.RecipientEmailAddress, email.RecipientName); var msg = MailHelper.CreateSingleTemplateEmail(from, to, email.TemplateId, email.DynamicTemplateData); await sendGridClient.SendEmailAsync(msg); }
private SendGridMessage BuildMessage(string templateId, string email, string username) { return(MailHelper.CreateSingleTemplateEmail( new EmailAddress(_configuration.Email, _configuration.Name), new EmailAddress(email, username), templateId, new { } )); }
public override async Task <string> SendTemplate(EmailConstants.EmailTypes emailType, Dictionary <string, string> emailAttributes) { var emailTemplateId = EmailTypeToSendgridId(emailType); var from = new EmailAddress(emailAttributes["FromEmail"], emailAttributes["FromUserName"]); var to = new EmailAddress(emailAttributes["ToEmail"], emailAttributes["ToUserName"]); var msg = MailHelper.CreateSingleTemplateEmail(from, to, emailTemplateId, emailAttributes); return(await SendViaSendGrid(msg)); }
public async Task <bool> SendEmailLogic(CustomerDto CustomerDto) { string apiKey = " "; //ADD API KEY SendGridClient Client = new SendGridClient(apiKey); var CustomersInDb = await GetList(); if (CustomersInDb == null) { return(false); } foreach (var customer in CustomersInDb) { customer.Email = isTestSend ? RecipientEmailAddress : customer.Email; var dynamicTemplateData = new Dictionary <string, object> { // dynamicTemplateData fields goes into the email template eg on html {{Name}} will have the value of Name below. { "Id", customer.Id }, { "Name", customer.Name }, { "Time", customer.Time }, { "email", customer.Email }, { "Description", customer.Description }, { "Cell", customer.Cell }, }; SendGridMessage msg = MailHelper.CreateSingleTemplateEmail( new EmailAddress(SenderEmailAddress, "ACME Info Tech"),// Sender/company name that will be on the email new EmailAddress(customer.Email), "d-template-id", dynamicTemplateData); switch (CustomerDto.Campaign) {//SetTemplateId IS THE EMAIL TEMPLATE LOCATED ON SENDGRID case "Maintenance": msg.SetTemplateId("d-7ddbf1d167f84b219460d81daf1ef79d"); break; case "Orders": msg.SetTemplateId("d-a612e58c3fb74832a9460d327f46d871"); break; } Response response = await Client.SendEmailAsync(msg); // POST PAYLOAD TO SENDGRID CustomerDto.EmailSent = (response.StatusCode.ToString() != "Accepted") ? false : true; if (response.StatusCode.ToString() != "Accepted") { // TODO: save record as sent } } return(true); }
public Response ExecuteTemplate(string recEmail, string recName, string templateID, object templateParameters) { var client = new SendGridClient(ApiKey); var from = new EmailAddress(SenderEmail, SenderName); var to = new EmailAddress(recEmail, recName); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateID, templateParameters); var response = client.SendEmailAsync(msg).Result; return(response); }
public virtual async Task SendSingleTemplateEmail(string from, string to, string templateID, object templateData) { Require.That(templateID != null, new ErrorCode("Unavailable", 403, "Required Sengrid template ID not configured in settins")); { var fromEmail = new EmailAddress(from); var toEmail = new EmailAddress(to); var msg = MailHelper.CreateSingleTemplateEmail(fromEmail, toEmail, templateID, templateData); await _client.SendEmailAsync(msg); } }
public async Task <HttpStatusCode> Send(string fromName, string toName, string toAddress, string fromAddress, string templateId, object data) { var to = new EmailAddress(toAddress, toName); var from = new EmailAddress(fromAddress, fromName); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, data); var response = await client.SendEmailAsync(msg); return(response.StatusCode); }
private static SendGridMessage CreateSendGridMessage(MailRequest request) { var from = new EmailAddress(request.From.Email, request.From.Name); var to = new EmailAddress(request.To.Email, request.To.Name); var message = MailHelper.CreateSingleTemplateEmail(from, to, request.Template.Id, request.Template.Data); message.AddHeader("notification-message-id", $"{request.MessageId}"); return(message); }
//This will send an email to notify that the user has a new friend on pollify. public static async Task NewFriend(string email, string username) { var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var from = fromEmail; var to = new EmailAddress(email); var templateId = "d-f3b0a49ae3904556abff7e73ca2e8fec"; string data = @"{'username': '******'}"; Object json = JsonConvert.DeserializeObject <Object>(data); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, json); var response = await client.SendEmailAsync(msg); }
//This will send an email with a link to reset his password. public static async Task ForgotPassword(string email, string username, string guid) { var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var from = fromEmail; var to = new EmailAddress(email); var templateId = "d-31eefdd1d29a472aa0b8ac6cbd3c3ad5"; string data = @"{ 'username': '******', 'guid': '" + guid + "'}"; Object json = JsonConvert.DeserializeObject <Object>(data); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, json); var response = await client.SendEmailAsync(msg); }
//This will send an email with a link to activate his account. public static async Task ActivationLink(string email, string username, string guid) { var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var from = fromEmail; var to = new EmailAddress(email); var templateId = "d-20817cd9e4f8414e92b3d3401f615df4"; string data = @"{ 'username': '******', 'guid': '" + guid + "'}"; Object json = JsonConvert.DeserializeObject <Object>(data); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, json); var response = await client.SendEmailAsync(msg); }
//This will send an email to notify the user that he has a new friend request. public static async Task FriedRequest(string email, string username) { var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var from = fromEmail; var to = new EmailAddress(email); var templateId = "d-4556857c0d1e46f6a234fbc227b1d69c"; string data = @"{ 'username': '******'}"; Object json = JsonConvert.DeserializeObject <Object>(data); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, json); var response = await client.SendEmailAsync(msg); }
//This will send an email to a person who has no account of Pollify public static async Task Invite(string email, string username) { var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var from = fromEmail; var to = new EmailAddress(email); var templateId = "d-464ce5ead1a342e6908e8fd4e078df46"; string data = @"{ 'username': '******'}"; Object json = JsonConvert.DeserializeObject <Object>(data); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, json); var response = await client.SendEmailAsync(msg); }
public async Task SendOrgApprovedEmail(EmailAddress from, EmailAddress to, string orgName, string orgId) { var templateParameters = new TemplateParameters { OpenReferralAppUrl = _settings.BaseAddress + $"manage-organisation/{orgId}", OrganisationName = orgName, UserName = JWTAttributesService.GetEmail(_httpContextAccessor.HttpContext.Request), }; var client = new SendGridClient(_apiKey); var msg = MailHelper.CreateSingleTemplateEmail(from, to, _settings.OrgApprovedTemplate, templateParameters); var response = await client.SendEmailAsync(msg); }
/// <summary> /// Sends an email with an expirating one time login link for them to gain access to their /// account and preferences in the application /// </summary> /// <param name="email">The email to send the login link to.</param> /// <param name="key">The generated <see cref="LoginKey"/> Kee property to send to the subscriber.</param> /// <returns>Bool as to the success of this call.</returns> public async Task <bool> SendLoginKeyEmailAsync(string email, string key) { var client = new SendGridClient(_emailSettings.ApiKey); var from = new EmailAddress(_emailSettings.LoginAddress, _emailSettings.FriendlyLogin); var jsonParameters = new { HANDLE = email, KEY = key, DOMAIN = $"https://{_emailSettings.Host}" }; var msg = MailHelper.CreateSingleTemplateEmail(from, new EmailAddress(email), _emailSettings.LoginKeyTemplateID, jsonParameters); var response = await client.SendEmailAsync(msg); return(response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.Accepted); }
public static async Task <Response> SendResetPasswordMailAsync(string apiKey, string to, string name, string hash) { var client = new SendGridClient(apiKey); var message = MailHelper.CreateSingleTemplateEmail(From, new EmailAddress(to), templateId: "d-c0d6363214d24d66834198724ea22502", dynamicTemplateData: new Dictionary <string, string> { { "user_name", name }, { "uri", $"https://priend.herokuapp.com/account/reset/{hash}" }, }); return(await client.SendEmailAsync(message)); }
public static async Task <Response> SendVerificationMailAsync(string apiKey, string to, string name, string hash) { var client = new SendGridClient(apiKey); var message = MailHelper.CreateSingleTemplateEmail(From, new EmailAddress(to), templateId: "d-bd57bec8ef924ee4926ad946a2f0c890", dynamicTemplateData: new Dictionary <string, string> { { "user_name", name }, { "uri", $"https://priend.herokuapp.com/account/verification/{hash}" }, }); return(await client.SendEmailAsync(message)); }
private async Task <Response> SendToSendGrid(Email email) { var client = new SendGridClient(email.ApiKey); var from = new EmailAddress(email.From.Email, email.From.Name); var msg = MailHelper.CreateSingleTemplateEmail(from, email.To, email.TemplateId, email.Substitutions ); return(await client.SendEmailAsync(msg)); }
/// <summary> /// Sends a custom email via SendGrid to the provided <see cref="Subscriber"/>. /// </summary> /// <param name="subscriber">A <see cref="Subscriber"/> to send notifications to.</param> /// <returns>Bool as to the success of this call with the EmailService.</returns> public async Task <bool> SendCustomEmailAsync(Subscriber subscriber) { var client = new SendGridClient(_emailSettings.ApiKey); var from = new EmailAddress(_emailSettings.NotifyAddress, _emailSettings.FriendlyNotify); var to = new EmailAddress(subscriber.Handle); var msg = MailHelper.CreateSingleTemplateEmail(from, to, "SET_TO_CUSTOM_TEMPLATE", null); var response = await client.SendEmailAsync(msg); return(response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.Accepted); }
public async Task <Response> SendEmailAsync(string email, string templateId, object templateData) { _sendGridClient = new SendGridClient(_emailConfig.ApiKey); var from = new EmailAddress(_emailConfig.FromEmail, _emailConfig.From); var to = new EmailAddress(email); var template = MailHelper.CreateSingleTemplateEmail(from, to, templateId, templateData); var response = await _sendGridClient.SendEmailAsync(template); _logger.LogInformation("An email has been sent to {Email} with status: {StatusCode}", email, response.StatusCode); return(response); }
} //set only via Secret Manager // public Task SendEmailAsync(string email, string subject, string message) // { // return Execute(Options.SendGridKey, subject, message, message, email, email); // } public Task <Response> SendVerificationEmailAsync(string email, string userName, string link, string templateId) { link = Options.BaseUrl + link; var dynamicTemplateData = new templateData { name = userName, button_url = link }; var to = new EmailAddress(email, userName); var from = new EmailAddress("*****@*****.**", "Gamitude"); var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, dynamicTemplateData); return(Execute(Options.SendGridKey, msg)); }