/// <summary> /// Sends the specified SendGrid <paramref name="message"/>. /// </summary> /// <param name="message">The SendGrid message to send.</param> /// <returns> /// The asynchronous task that can be awaited. The Task.Result is the Sitefinity SendResult /// that indicates the weather the sending was successful or not.</returns> public async Task <SendResult> SendAsync(SG.SendGridMessage message) { // Create a Web transport for sending email. var transportWeb = new SendGridClient(this.ApiKey); try { // No need for asynchronous execution since the sender is invoked in a separate thread // dedicated to sending the messages. var response = await transportWeb.SendEmailAsync(message); if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { var responseBody = await response.Body.ReadAsStringAsync(); return(SendResult.ReturnFailed(new Exception(responseBody))); } return(SendResult.ReturnSuccess()); } catch (HttpException ex) { // HttpExceptions are expected so we just return that the sending failed. return(SendResult.ReturnFailed(ex)); } catch (Exception ex) { // TODO: run those exceptions through a Notifications exception handling policy before returning the result. return(SendResult.ReturnFailed(ex)); } }
public SendGridMessage BuildSurveyCompletedMessage() { var mailMessage = new SendGrid.Helpers.Mail.SendGridMessage(); var html = @"<html><body><h1>Test</h1></body></html>"; mailMessage.HtmlContent = html; return(mailMessage); }
public Task SendAsync(IdentityMessage message) { EmailAddress from = new EmailAddress("*****@*****.**", "Coding Cookware Administrator"); EmailAddress to = new EmailAddress(message.Destination); SendGridMessage sendGridMessage = MailHelper.CreateSingleEmail(from, to, message.Subject, Regex.Replace(message.Body, @"<(.|\n)*?>", ""), message.Body); return(_client.SendEmailAsync(sendGridMessage)); }
public Task SendAsync(IdentityMessage message) { // Plug in your email service here to send an email. SendGrid.SendGridClient client = new SendGridClient(apiKey: "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"); SendGrid.Helpers.Mail.SendGridMessage sgm = new SendGrid.Helpers.Mail.SendGridMessage(); sgm.AddTo(new EmailAddress(message.Destination)); sgm.HtmlContent = message.Body; sgm.Subject = message.Subject; sgm.SetFrom("*****@*****.**"); return(client.SendEmailAsync(sgm)); }
private void AddGlobalProperties(SG.SendGridMessage message, IMessageJobRequest messageJob) { message.From = new SG.EmailAddress(messageJob.SenderEmailAddress, messageJob.SenderName); message.Subject = messageJob.MessageTemplate.Subject; message.PlainTextContent = messageJob.MessageTemplate.PlainTextVersion; message.HtmlContent = messageJob.MessageTemplate.BodyHtml; if (messageJob.CustomMessageHeaders != null && messageJob.CustomMessageHeaders.Count > 0) { message.CustomArgs = new Dictionary <string, string>(messageJob.CustomMessageHeaders); } }
public async Task SendAsync(MailMessage message) { var msg = new SendGrid.Helpers.Mail.SendGridMessage() { HtmlContent = message.Body, From = new EmailAddress(String.IsNullOrWhiteSpace(message.From) ? _mailServiceConfiguration.DefaultSender : message.From), Subject = message.Subject, }; msg.AddTos(message.To.Select(t => new EmailAddress(t)).ToList()); await _sendgridClient.SendEmailAsync(msg); }
/// <summary> /// Constructs a SendGrid message based on the specified <paramref name="messageJob"/> and <paramref name="subscribers"/>. /// </summary> /// <param name="messageJob">The Sitefinity message job from which to construct a SendGrid message.</param> /// <param name="subscribers">The subscribers for the message.</param> /// <returns>A SendGrid message with configured subscribers, substitutions, subject template etc.</returns> public SG.SendGridMessage ConstructMessage(IMessageJobRequest messageJob, IEnumerable <ISubscriberResponse> subscribers) { //// TODO: raise some events here. There is a high chance someone would like //// to extend the message before or after it has been constructed in the following code. var message = new SG.SendGridMessage(); message.Personalizations = new List <SG.Personalization>(); this.AddGlobalProperties(message, messageJob); // Adding per subscriber information that is needed to build the message template and the subscriber id custom message header. this.AddSubscribersInfo(message, messageJob, subscribers); return(message); }
public IHttpActionResult PostSystem_Logging([FromBody] System_Logging system_Logging) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var syslog = new System_Logging { Id = 0, EnteredDate = system_Logging.EnteredDate, logMessage = '@' + system_Logging.logMessage.ToString(), logRouteInfo = system_Logging.logRouteInfo, loguserName = system_Logging.loguserName != null ? system_Logging.loguserName : "******" }; db.System_Logging.Add(syslog); db.SaveChanges(); var client = new SendGridClient("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"); var msg = new SendGrid.Helpers.Mail.SendGridMessage() { From = new EmailAddress("*****@*****.**"), Subject = "HLAPointErrorNotification<DonotReply>", PlainTextContent = "HLAPointErrorNotification", HtmlContent = "<strong>ErrorReportedFor :</strong>" + syslog.loguserName + "</br>" + "<strong>Resource Accessed :</strong>" + system_Logging.logRouteInfo + "</br>" + "<strong>ErrorDetails :</strong>" + system_Logging.logMessage + "</br>" }; //var emailst = new List<EmailAddress>(); //var emailaddr1 = new EmailAddress("*****@*****.**"); //emailst.Add(emailaddr1); //var emailaddr2 = new EmailAddress("*****@*****.**"); //emailst.Add(emailaddr1); //msg.AddTos(emailst); msg.AddTo(new EmailAddress("*****@*****.**", "Test User")); var response = client.SendEmailAsync(msg); return(CreatedAtRoute("DefaultApi", new { id = system_Logging.Id }, system_Logging)); } catch (Exception ex) { return(Json(ex)); } }
public Task Execute(string apiKey, string subject, string message, string email) { var client = new SendGridClient(apiKey); var msg = new SendGridMessage() { // From = new EmailAddress("*****@*****.**", "LOVE IS..."), From = new EmailAddress("*****@*****.**", "LOVE IS..."), Subject = subject, PlainTextContent = message, HtmlContent = message }; msg.AddTo(new EmailAddress(email)); // Disable click tracking. // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html msg.SetClickTracking(false, false); return(client.SendEmailAsync(msg)); }
public async Task <IActionResult> Index(string email, string user) { var apiKey = System.Environment.GetEnvironmentVariable("sendgrid"); var client = new SendGridClient("sendgrid"); SendGrid.Helpers.Mail.SendGridMessage message = new SendGrid.Helpers.Mail.SendGridMessage(); { message.AddTo(new EmailAddress(("*****@*****.**"))); message.Subject = "Contact Form"; message.SetFrom("*****@*****.**"); message.AddContent("text/plain", "Thank You for filling out this contact form" + user + "We will get back to you very shortly"); message.AddContent("text/html", "Thank You for filling out this contact form" + user + "We will get back to you very shortly"); message.SetTemplateId("cae92438-518b-473a-b985-fd2f66b7c947"); }; await _sendGridClient.SendEmailAsync(message); return(RedirectToAction("Index", "Home")); }
/// <summary> /// Conducts the sending of emails to a single recipeient /// </summary> /// <param name="message">The Message details to send</param> /// <returns>The Status of the email sent</returns> public Task configSendGridAsync(IdentityMessage message) { var client = new SendGridClient("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"); var SGMessage = new SendGrid.Helpers.Mail.SendGridMessage() { From = new EmailAddress( "*****@*****.**", "DocuMate Team"), Subject = message.Subject, PlainTextContent = message.Body, HtmlContent = message.Body }; SGMessage.AddTo(new EmailAddress(message.Destination)); var response = client.SendEmailAsync(SGMessage); return(response); }
/// <summary> /// /// Conducts the sending of emails to an email address /// </summary> /// <param name="message">message details</param> /// <returns>The Status of sent item</returns> public Task configSendGridAsync(IdentityMessage message) { var client = new SendGridClient("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"); var SGMessage = new SendGrid.Helpers.Mail.SendGridMessage() { From = new EmailAddress( "*****@*****.**", "FX Traders"), Subject = message.Subject, PlainTextContent = message.Body, HtmlContent = message.Body }; SGMessage.AddTo(new EmailAddress(message.Destination)); var response = client.SendEmailAsync(SGMessage); return(response); }
private Task Execute(string sendGridKey, string subject, string message, string email) { var client = new SendGridClient(sendGridKey); var msg = new SendGrid.Helpers.Mail.SendGridMessage() { From = new EmailAddress("*****@*****.**", "UNF HackAThon"), Subject = subject, PlainTextContent = message, HtmlContent = message }; msg.AddTo(new EmailAddress(email)); try { return(client.SendEmailAsync(msg)); } catch (Exception ex) { } return(null); }
public async Task <Response> Execute(string apiKey, string subject, string message, string email) { var client = new SendGridClient(apiKey); var msg = new SendGrid.Helpers.Mail.SendGridMessage() { From = new EmailAddress(EmailFrom, EmailName), Subject = subject, PlainTextContent = message, HtmlContent = message, }; msg.AddTo(new EmailAddress(email)); // Disable click tracking. // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html msg.SetClickTracking(false, false); var response = await client.SendEmailAsync(msg); return(response); }
private void AddSubscribersInfo(SG.SendGridMessage message, IMessageJobRequest messageJob, IEnumerable <ISubscriberResponse> subscribers) { var replacementTags = this.GetReplacementTags(messageJob).ToList(); // Filling in the substitutions data structure with per subscriber values via persionalizations. foreach (var subscriber in subscribers) { // TODO: validate subscribers email addresses // TODO: add email + recipient name as TO address. var personalization = new SG.Personalization() { Tos = new List <SG.EmailAddress>() { new SG.EmailAddress(subscriber.Email) }, Substitutions = this.CalculateSubstitutions(replacementTags, subscriber.ToDictionary()) }; message.Personalizations.Add(personalization); } }