public ActionResult Checkout(ProposalModel model)
        {
            string apiKey = ConfigurationManager.AppSettings["SendGrid.Key"];

            SendGrid.SendGridAPIClient client = new SendGrid.SendGridAPIClient(apiKey);

            SendGrid.Helpers.Mail.Email from = new SendGrid.Helpers.Mail.Email("*****@*****.**");
            string subject = "Couture Events: New Client!";

            SendGrid.Helpers.Mail.Email to = new SendGrid.Helpers.Mail.Email("*****@*****.**");

            Content content = new Content("text/html", " ");
            Mail    mail    = new Mail(from, subject, to, content);

            mail.TemplateId = "13a5ec2f-0260-4134-a3a2-aeacbe6882ec";
            mail.Personalization[0].AddSubstitution("-brideName-", model.Customer.BrideFirstName + "  " + model.Customer.BrideLastName);
            mail.Personalization[0].AddSubstitution("-groomName-", model.Customer.GroomFirstName + " " + model.Customer.GroomLastName);
            mail.Personalization[0].AddSubstitution("-phoneNumber-", model.Customer.PhoneNumber);
            mail.Personalization[0].AddSubstitution("-email-", model.Customer.Email);
            mail.Personalization[0].AddSubstitution("-weddingDate-", model.Customer.WeddingDate.ToString());
            mail.Personalization[0].AddSubstitution("-numberOfGuests-", model.Customer.NumberOfGuests.ToString());
            mail.Personalization[0].AddSubstitution("-serviceName-", model.Service.Name);
            mail.Personalization[0].AddSubstitution("-address-", model.Customer.Address);
            mail.Personalization[0].AddSubstitution("-groomsmen-", model.Customer.NumberOfGroomsmen.ToString());
            mail.Personalization[0].AddSubstitution("-serviceName-", model.Customer.NumberOfBridesmaids.ToString());

            client.client.mail.send.post(requestBody: mail.Get());
            return(RedirectToAction("Index", "Home"));
        }
        public async Task SendHtmlEmail(string subject, string toEmail, string content)
        {
            string apiKey = _configurationService.Email.ApiKey;
            dynamic sg = new SendGridAPIClient(apiKey);

            Email from = new Email(_configurationService.Email.From);
            Email to = new Email(toEmail);
            Content mailContent = new Content("text/html", content);
            Mail mail = new Mail(from, subject, to, mailContent);

            var personalization = new Personalization();
            personalization.AddTo(to);

            if (_configurationService.Email.Bcc != null && _configurationService.Email.Bcc.Any())
            {

                foreach (var bcc in _configurationService.Email.Bcc)
                {
                    personalization.AddBcc(new Email(bcc));
                }
                mail.AddPersonalization(personalization);
            }

            dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());

            if (response.StatusCode != System.Net.HttpStatusCode.Accepted)
            {
                var responseMsg = response.Body.ReadAsStringAsync().Result;
                _logger.Error($"Unable to send email: {responseMsg}");
            }
        }
        public async Task SendAsync(IdentityMessage message)
        {
            //var myMessage = new SendGridMessage();
            //myMessage.AddTo(message.Destination);
            //myMessage.From = new MailAddress("*****@*****.**", "fzrain");
            //myMessage.Subject = message.Subject;
            //myMessage.Text = message.Body;
            //myMessage.Html = message.Body;

            //var credentials = new NetworkCredential("fzy55601", "fzy86087108");
            //// Create a Web transport for sending email.
            //var transportWeb = new Web(credentials);
            //// Send the email.
            //await transportWeb.DeliverAsync(myMessage);

            String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
            dynamic sg = new SendGridAPIClient(apiKey);

            Email from = new Email("*****@*****.**");
            String subject = "Hello World from the SendGrid CSharp Library";
            Email to = new Email("*****@*****.**");
            Content content = new Content("text/plain", "Textual content");
            Mail mail = new Mail(from, subject, to, content);

            dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
        }
 public static async Task SendEmail(string email, string subject, string content, EmailConfig config)
 {
     dynamic sg = new SendGridAPIClient(config.SendGridApiKey);
     Email from = new Email(config.EmailFrom);
     Email to = new Email(email);
     Mail mail = new Mail(from, subject, to, new Content("text/html", content));
     dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
 }
        public void SendEmail(EmailModel email)
        {
            dynamic sg = new SendGridAPIClient("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");

            Email from = new Email("*****@*****.**","Brilliant Engineering Ltd");
            String subject = email.Subject;
            Email to = new Email(email.EmailAddress);
            Content content = new Content("text/html", email.Body);
            Mail mail = new Mail(from, subject, to, content);

            dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
        }
Beispiel #6
0
 public void SendEmail(EmailViewModel emailDetails)
 {
     string body = File.ReadAllText(HttpContext.Current.Server.MapPath("~/Partials/Emails/AdminNotificationTemplate.html"));
     body = body.Replace("{UserName}", _toPerson);
     body = body.Replace("{EventTitle}", emailDetails.Title);
     body = body.Replace("{ShortDescription}", emailDetails.Body);
     body = body.Replace("{TodaysDate}", "" + GetNZLocalTime());
     body = body.Replace("{LongDescription}", emailDetails.Footer);
     string subject = "" + emailDetails.Subject;
     dynamic sg = new SendGridAPIClient(_emailApiKey);
     Email from = new Email(_fromEmail, _fromPerson);
     Email to = new Email(_toEmail);
     Content content = new Content("text/html", body);
     Mail mail = new Mail(from, subject, to, content);
     dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
 }
Beispiel #7
0
        private async Task SendEmailAsync(EmailMessage message)
        {
            dynamic sendGrid = new SendGridAPIClient(MailAccount);

            var from = new Email(SendAddress);
            var to = new Email(message.Destination);
            var content = new Content("text/plain", message.Body);
            var mail = new Mail(from, message.Subject, to, content);

            try
            {
                dynamic response = await sendGrid.client.mail.send.post(requestBody: mail.Get());
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message + " SendGrid probably not configured correctly.");
            }
        }
        public async Task Send(Indulgence indulgence, string indulgenceFilePath)
        {
            dynamic sg             = new SendGrid.SendGridAPIClient(_sendGridApiKey);
            var     fromAddress    = ConfigurationManager.AppSettings["SendGridFromAddress"];
            var     fromName       = ConfigurationManager.AppSettings["SendGridFromName"];
            var     indulgenceLink = string.Format("{0}/indulgence/pdf/{1}",
                                                   ConfigurationManager.AppSettings["WebsiteHostName"], indulgence.Guid);
            string data = @"{
'content': [
    {
      'type': 'text/html', 
      'value': '<html><p>Hello good person,</p><p>Please accept this *genuine plenary indulgence. Be sure to present it when you are received in purgatory.</p><p><a href=\'" + indulgenceLink + @"\'>Click here for the PDF version</a></p><p>Send this to your friends, gloat about it, and encourage them to perform good acts too!</p><p><small>*not endorsed by the Catholic church</small></p></html>'
    }
  ],
'from': {
    'email': '" + fromAddress + @"', 
    'name': '" + fromName + @"'
  },
'personalizations': 
[
    {
        'to': [{
          'email': '" + indulgence.DonorEmailAddress + @"', 
          'name': '" + (string.IsNullOrWhiteSpace(indulgence.DonorEmailAddress) ? "" : indulgence.DonorEmailAddress) + @"'
        }]
    }
], 
  'reply_to': {
    'email': '" + fromAddress + @"', 
    'name': '" + fromName + @"'
  }, 
  'subject': 'Bless you! Please accept your indulgence'
}";

            Object json = JsonConvert.DeserializeObject <Object>(data);

            data = json.ToString();
            dynamic response = await sg.client.mail.send.post(requestBody : data);

            _log.InfoFormat("sent an email to " + indulgence.DonorEmailAddress);
            _log.InfoFormat("response code: {0}, result: {1}, headers: {2}",
                            response.StatusCode, response.Body.ReadAsStringAsync().Result, response.Headers.ToString());
        }
        public async Task Send(Indulgence indulgence, string indulgenceFilePath)
        {
                dynamic sg = new SendGrid.SendGridAPIClient(_sendGridApiKey);
                var fromAddress = ConfigurationManager.AppSettings["SendGridFromAddress"];
                var fromName = ConfigurationManager.AppSettings["SendGridFromName"];
                var indulgenceLink = string.Format("{0}/indulgence/pdf/{1}",
                                    ConfigurationManager.AppSettings["WebsiteHostName"], indulgence.Guid);
                string data = @"{
'content': [
    {
      'type': 'text/html', 
      'value': '<html><p>Hello good person,</p><p>Please accept this *genuine plenary indulgence. Be sure to present it when you are received in purgatory.</p><p><a href=\'" + indulgenceLink + @"\'>Click here for the PDF version</a></p><p>Send this to your friends, gloat about it, and encourage them to perform good acts too!</p><p><small>*not endorsed by the Catholic church</small></p></html>'
    }
  ],
'from': {
    'email': '"+ fromAddress+ @"', 
    'name': '" + fromName + @"'
  },
'personalizations': 
[
    {
        'to': [{
          'email': '" + indulgence.DonorEmailAddress + @"', 
          'name': '" + (string.IsNullOrWhiteSpace(indulgence.DonorEmailAddress) ? "" : indulgence.DonorEmailAddress) + @"'
        }]
    }
], 
  'reply_to': {
    'email': '" + fromAddress + @"', 
    'name': '" + fromName + @"'
  }, 
  'subject': 'Bless you! Please accept your indulgence'
}";

                Object json = JsonConvert.DeserializeObject<Object>(data);
                data = json.ToString();
                dynamic response = await sg.client.mail.send.post(requestBody: data);

                _log.InfoFormat("sent an email to " + indulgence.DonorEmailAddress);
                _log.InfoFormat("response code: {0}, result: {1}, headers: {2}",
                    response.StatusCode, response.Body.ReadAsStringAsync().Result, response.Headers.ToString());
        }
Beispiel #10
0
        private async Task<dynamic> SendEmailConfirmation(ApplicationUser user)
        {
            //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

            // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
            // Send an email with this link
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { token = user.Id, code = code }, protocol: Request.Url.Scheme);
            const string apiKey = "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";
            dynamic sg = new SendGridAPIClient(apiKey);

            var from = new Email("*****@*****.**");
            var subject = "Confirm your YOURSITE account";
            var to = new Email(user.Email);
            var content = new Content("text/html", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
            var mail = new Mail(from, subject, to, content);

            dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
            //await sg.client.mail.send.post(requestBody: mail.Get());
            return response;
        }
Beispiel #11
0
        /// <summary>
        /// Sends the generated report.
        /// </summary>
        /// <param name="log">The writer for logging.</param>
        /// <param name="clubInfo">Info about the club of interest</param>
        /// <param name="subject">The email subject</param>
        /// <param name="body">The email body</param>
        /// <returns>A task that completes when the email has been sent.</returns>
        private static async Task SendDailyReportEmail(TextWriter log, ClubInfo clubInfo, string subject, string body)
        {
            dynamic sg = new SendGridAPIClient(EnvironmentDefinition.Instance.SendGridApiKey);

            Email from = new Email(clubInfo.DailyReportSender);
            Content content = new Content("text/html", body);

            string[] recipients = new string[0];

            if (EnvironmentDefinition.Instance.IsDevelopment)
            {
                recipients = new string[] { CloudConfigurationManager.GetSetting("DeveloperEmail", false) };
            }
            else if (EnvironmentDefinition.Instance.IsProduction)
            {
                recipients = clubInfo.DailyReportRecipients.Split(',');
            }

            foreach (var recipient in recipients)
            {
                try
                {
                    Email to = new Email(recipient);
                    Mail mail = new Mail(from, subject, to, content);

                    dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());

                    log.WriteLine($"Sent report email to {recipient}");
                }
                catch (Exception ex)
                {
                    log.WriteLine($"Failed to send report email to {recipient}: {ex.Message}");
                }
            }
        }
Beispiel #12
-1
        public async Task<bool> SendAsync(EmailMessage email, bool deleteAttachmentes, params string[] attachments)
        {
            var config = this.Config as Config;

            if (config == null)
            {
                email.Status = Status.Cancelled;
                return false;
            }

            try
            {
                email.Status = Status.Executing;

                var personalization = new Personalization
                {
                    Subject = email.Subject
                };


                var message = new Mail
                {
                    From = new Email(email.FromEmail, email.FromName),
                    Subject = email.Subject
                };

                if (!string.IsNullOrWhiteSpace(email.ReplyToEmail))
                {
                    message.ReplyTo = new Email(email.ReplyToEmail, email.ReplyToName);
                }


                foreach (var address in email.SentTo.Split(','))
                {
                    personalization.AddTo(new Email(address.Trim()));
                }


                message.AddPersonalization(personalization);

                var content = new Content();
                content.Value = email.Message;

                if (email.IsBodyHtml)
                {
                    content.Type = "text/html";
                }
                else
                {
                    content.Type = "text/plain";
                }

                message.AddContent(content);

                message = AttachmentHelper.AddAttachments(message, attachments);

                var sg = new SendGridAPIClient(config.ApiKey, "https://api.sendgrid.com");
                dynamic response = await sg.client.mail.send.post(requestBody: message.Get());

                System.Net.HttpStatusCode status = response.StatusCode;

                switch (status)
                {
                    case System.Net.HttpStatusCode.OK:
                    case System.Net.HttpStatusCode.Created:
                    case System.Net.HttpStatusCode.Accepted:
                    case System.Net.HttpStatusCode.NoContent:
                        email.Status = Status.Completed;
                        break;
                    default:
                        email.Status = Status.Failed;
                        break;
                }

                return true;
            }
            // ReSharper disable once CatchAllClause
            catch (Exception ex)
            {
                email.Status = Status.Failed;
                Log.Warning(@"Could not send email to {To} using SendGrid API. {Ex}. ", email.SentTo, ex);
            }
            finally
            {
                if (deleteAttachmentes)
                {
                    FileHelper.DeleteFiles(attachments);
                }
            }

            return false;
        }