public async Task SendEmailMessageAsync(string toAddress, string fromAddress, string fromName, string subject, string html, 
            EmailSendSuccessDelegate onSuccess, 
            IDictionary<string, List<string>> substitutions,
            Action<string, IDictionary<string, string>> logIssue)
        {
            var emailMuteString = Microsoft.Azure.CloudConfigurationManager.GetSetting("BlackBarLabs.Web.SendMailService.Mute");
            var emailMute = String.Compare(emailMuteString, "true", true) == 0;
            var copyEmail = Microsoft.Azure.CloudConfigurationManager.GetSetting("BlackBarLabs.Web.SendMailService.CopyAllAddresses");

            if (!emailMute)
            {
                if (!EmailIsInMuteAddresses(toAddress))
                {
                    await
                        DispatchMessageAsync(toAddress, fromAddress, fromName, subject, html, onSuccess, substitutions,
                            logIssue);
                }
            }
            if (!string.IsNullOrEmpty(copyEmail))
            {
                var toAddresses = copyEmail.Split(',');
                foreach (var address in toAddresses)
                {
                    await DispatchMessageAsync(address, fromAddress, fromName, subject, html, onSuccess, substitutions, logIssue);
                }
                return;
            }
        }
 public Task SendEmailMessageAsync(string toAddress, string fromAddress,
     string fromName, string subject, string html, EmailSendSuccessDelegate onSuccess,
     IDictionary<string, List<string>> substitution, Action<string, IDictionary<string, string>> logIssue)
 {
     return this.SendEmailMessageCallback.Invoke(
         toAddress, fromAddress, fromName, subject, html, substitution);
 }
        public async Task SendEmailMessageAsync(string toAddress, string fromAddress, string fromName, string subject, 
            string template,
            EmailSendSuccessDelegate onSuccess,
            IDictionary<string, List<string>> substitutions,
            Action<string, IDictionary<string, string>> logIssue)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(toAddress);
            myMessage.From = new MailAddress(fromAddress, fromName);
            myMessage.Subject = subject;
            myMessage.EnableTemplateEngine(template);
            

            if (default(IDictionary<string, List<string>>) != substitutions)
            {
                foreach (var substitutionsKvp in substitutions)
                    myMessage.AddSubstitution(substitutionsKvp.Key, substitutionsKvp.Value);
            }

            // Create credentials, specifying your user name and password.
            var credentials = new NetworkCredential(username, password);

            // Create an Web transport for sending email.
            var transportWeb = new global::SendGrid.Web(credentials);

            // Send the email, which returns an awaitable task.
            try
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            catch (InvalidApiRequestException ex)
            {
                var details = new StringBuilder();

                details.Append("ResponseStatusCode: " + ex.ResponseStatusCode + ".   ");
                for (int i = 0; i < ex.Errors.Count(); i++)
                {
                    details.Append(" -- Error #" + i.ToString() + " : " + ex.Errors[i]);
                }

                throw new ApplicationException(details.ToString(), ex);
            }
            onSuccess.Invoke(toAddress);
        }