public void ScheduleMulti()
        {
            var client = new SendGridClient(ConfigurationManager.AppSettings["ApiKey"]);

            var sendAt = DateTimeOffset.Now.AddMinutes(15);

            for (int i = 0; i < 5; i++)
            {
                var message = new SendGridMessage();

                message.To.Add(ConfigurationManager.AppSettings["MailTo"]);
                message.From = ConfigurationManager.AppSettings["MailFrom"];

                message.Header.AddSubstitution("-name-", "抱かれたい男 No.1");
                message.Header.AddSendAt(sendAt);

                message.Subject = "-name- さんへ" + i;
                message.Text = "-name- さん";
                message.Html = "<p>-name- さん</p>";

                client.Send(message);

                Thread.Sleep(200);
            }
        }
        public void Schedule()
        {
            var client = new SendGridClient(ConfigurationManager.AppSettings["ApiKey"]);

            var message = new SendGridMessage();

            message.To.Add(ConfigurationManager.AppSettings["MailTo"]);
            message.From = ConfigurationManager.AppSettings["MailFrom"];

            message.Header.AddSubstitution("-name-", "抱かれたい男 No.1");
            message.Header.AddSendAt(DateTimeOffset.Now.AddSeconds(30));

            message.Subject = "-name- さんへ";
            message.Text = "-name- さん";
            message.Html = "<p>-name- さん</p>";

            client.Send(message);
        }
        public async Task SendAsync()
        {
            var client = new SendGridClient(ConfigurationManager.AppSettings["ApiKey"]);

            var message = new SendGridMessage();

            message.To.Add(ConfigurationManager.AppSettings["MailTo"]);
            message.From = ConfigurationManager.AppSettings["MailFrom"];

            message.Header.AddSubstitution("-name-", "抱かれたい男 No.1");
            message.UseFooter("html", "text");

            message.Subject = "-name- さんへ";
            message.Text = "-name- さん";
            message.Html = "<p>-name- さん</p>";

            await client.SendAsync(message);
        }
        public void Send()
        {
            var client = new SendGridClient(new NetworkCredential(ConfigurationManager.AppSettings["ApiUser"], ConfigurationManager.AppSettings["ApiKey"]));

            var message = new SendGridMessage();

            message.To.Add(ConfigurationManager.AppSettings["MailTo"]);
            message.From = ConfigurationManager.AppSettings["MailFrom"];

            message.Header.AddSubstitution("-name-", "抱かれたい男 No.1");
            message.UseFooter("html", "text");

            message.Subject = "-name- さんへ";
            message.Text = "-name- さん";
            message.Html = "<p>-name- さん</p>";

            client.Send(message);
        }
Exemple #5
0
        private Task Execute(string sendGridKey, string subject, string message, string email)
        {
            var client = new SendGridClient(sendGridKey);

            var msg = new SendGridMessage()
            {
                From             = new EmailAddress("*****@*****.**", "Spice Restaurant"),
                Subject          = subject,
                PlainTextContent = message,
                HtmlContent      = message
            };

            msg.AddTo(new EmailAddress(email));
            try
            {
                return(client.SendEmailAsync(msg));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
        public Task Execute(string apiKey, string subject, string message, List <string> emails)
        {
            var client = new SendGridClient(apiKey);

            var msg = new SendGridMessage()
            {
                From = new EmailAddress(_configuration["SendGrid:SenderEmail"], _configuration["SendGrid:SenderName"]),

                Subject          = subject,
                PlainTextContent = message,
                HtmlContent      = message
            };

            foreach (var email in emails)
            {
                msg.AddTo(new EmailAddress(email));
            }

            Task response = client.SendEmailAsync(msg);

            return(response);
        }
Exemple #7
0
        public static bool SendEmailUsingSendGrid(List <string> to, string subject, string body)
        {
            //create a new message object
            var message = new SendGridMessage();

            //set the message recipients
            foreach (var recipient in to)
            {
                message.AddTo(recipient);
            }

            message.From    = new MailAddress(FromAddress, DisplayName);
            message.Html    = body;
            message.Subject = subject;

            //create an instance of the Web transport mechanism
            var transportInstance = new Web(new NetworkCredential(sendGridUserID, sendGridPassword));

            //send the mail
            transportInstance.DeliverAsync(message);
            return(true);
        }
Exemple #8
0
        internal static async void Send(string to, string from, string subject, string body, TraceWriter log)
        {
            var apiKey = Environment.GetEnvironmentVariable("sendgrid-key");

            if (string.IsNullOrEmpty(from))
            {
                from = Environment.GetEnvironmentVariable("default-frommail");
            }
            ;

            var client = new SendGridClient(apiKey);
            var msg    = new SendGridMessage()
            {
                From             = new EmailAddress(from, "DuraShop Team"),
                Subject          = subject,
                PlainTextContent = body,
                HtmlContent      = $"<strong>{body}</strong>"
            };

            msg.AddTo(new EmailAddress(to, "Arne Anka"));
            var response = await client.SendEmailAsync(msg);
        }
        public Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            var client = new SendGridClient(Options.SendGridKey);
            var msg    = new SendGridMessage()
            {
                From             = new EmailAddress("*****@*****.**", "Rent a Car"),
                Subject          = subject,
                PlainTextContent = htmlMessage,
                HtmlContent      = htmlMessage
            };

            msg.AddTo(new EmailAddress(email));

            try
            {
                return(client.SendEmailAsync(msg));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Exemple #10
0
        public void SendEmail(List <String> destinatarios, String asunto, String body)
        {
            try
            {
                var templateReder = new TemplateRender();
                var myMessage     = new SendGridMessage();

                myMessage.AddTo(destinatarios);
                myMessage.From    = new MailAddress(emailFrom, emailFromName);
                myMessage.Subject = asunto;
                myMessage.Html    = body;

                var transporWeb = new Web(credentials);
                if (transporWeb != null)
                {
                    transporWeb.DeliverAsync(myMessage);
                }
            }
            catch
            {
            }
        }
        private async Task SendEmailAsync(
            Func <string> subjectBuilder,
            Func <string> contentBuilder,
            CancellationToken cancellationToken = default)
        {
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress(this.options.Mail.FromEmail, "Marketplace Dashboard"));

            var recipients = new List <EmailAddress> {
                new EmailAddress(this.options.Mail.OperationsTeamEmail)
            };

            msg.AddTos(recipients);

            msg.SetSubject(subjectBuilder());

            msg.AddContent(MimeType.Html, contentBuilder());

            var client   = new SendGridClient(this.options.Mail.ApiKey);
            var response = await client.SendEmailAsync(msg, cancellationToken);
        }
        public EmailResponse Send(EmailContract contract)
        {
            var emailMessage = new SendGridMessage()
            {
                From        = new EmailAddress(contract.FromEmailAddress, contract.Alias),
                Subject     = contract.Subject,
                HtmlContent = contract.Body
            };

            emailMessage.AddTo(new EmailAddress(contract.ToEmailAddress));
            if (!string.IsNullOrWhiteSpace(contract.BccEmailAddress))
            {
                emailMessage.AddBcc(new EmailAddress(contract.BccEmailAddress));
            }

            if (!string.IsNullOrWhiteSpace(contract.CcEmailAddress))
            {
                emailMessage.AddBcc(new EmailAddress(contract.CcEmailAddress));
            }

            return(ProcessResponse(_client.SendEmailAsync(emailMessage).Result));
        }
Exemple #13
0
        public Task SendEmailAsync(string email, string subject, string body)
        {
            SendGridMessage message = new SendGridMessage();

            message.AddTo(email);
            message.From    = new System.Net.Mail.MailAddress("*****@*****.**", "HERO CrossFit Management");
            message.Subject = subject;
            message.Html    = body;

            NetworkCredential credentials = new NetworkCredential(SendGridUser, SendGridPass);

            Web transportWeb = new Web(credentials);

            if (transportWeb != null)
            {
                return(transportWeb.DeliverAsync(message));
            }
            else
            {
                return(Task.FromResult(0));
            }
        }
Exemple #14
0
        private Task ContactFormEmailExecute(string apiKey, string subject, string message, string email)
        {
            var client = new SendGridClient(apiKey);

            message = EscapeJavascriptCharacters(message).Result;

            var msg = new SendGridMessage()
            {
                From             = new EmailAddress(email),
                Subject          = subject,
                PlainTextContent = message,
                HtmlContent      = message,
            };

            msg.AddTo(new EmailAddress(ContactFormEmailDestination, ContactOfficialName));

            // Disable click tracking.
            // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html
            msg.SetClickTracking(false, false);

            return(client.SendEmailAsync(msg));
        }
Exemple #15
0
        public void mail()
        {
            var username = "******";
            var pswd     = "visiblepassword";

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

            myMessage.AddTo("*****@*****.**");
            myMessage.From    = new MailAddress("*****@*****.**", "Jane Doe");
            myMessage.Subject = "Here is your model file";
            myMessage.Text    = "FILE";

            myMessage.AddAttachment(@"C:/Saved.obj");


            var transportWeb = new Web(credentials);

            // Send the email.
            transportWeb.Deliver(myMessage);
        }
        public Task SendEmailAsync(string email, string subject, string message)
        {
            //return Exceute(Options.SendGridKey, subject, message, email);
            var client = new SendGridClient(Options.SendGridKey);
            var msg    = new SendGridMessage()
            {
                From             = new EmailAddress("*****@*****.**", "Foods Restaurant"),
                Subject          = subject,
                PlainTextContent = message,
                HtmlContent      = message
            };

            msg.AddTo(new EmailAddress(email));
            try
            {
                return(client.SendEmailAsync(msg));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Exemple #17
0
        /// <summary>
        ///     This feature allows you to create a message template, and specify different replacement
        ///     strings for each specific recipient
        /// </summary>
        public void AddSubstitutionValues()
        {
            //create a new message object
            var message = new SendGridMessage();

            //set the message recipients
            foreach (var recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Text = "Hi %name%! Pleased to meet you!";

            //set the message subject
            message.Subject = "Testing Substitution Values";

            //This replacement key must exist in the message body
            var replacementKey = "%name%";

            //There should be one value for each recipient in the To list
            var substitutionValues = new List <String> {
                "Mr Foo", "Mrs Raz"
            };

            message.AddSubstitution(replacementKey, substitutionValues);

            //create an instance of the SMTP transport mechanism
            var transportInstance = new Web(new NetworkCredential(_username, _password));

            //enable bypass list management
            message.EnableBypassListManagement();

            //send the mail
            transportInstance.Deliver(message);
        }
Exemple #18
0
        // Use NuGet to install SendGrid (Basic C# client lib)
        private async Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                ConfigurationManager.AppSettings["EmailService.SenderAddress"],
                ConfigurationManager.AppSettings["EmailService.SenerName"]);
            myMessage.Subject = message.Subject;
            myMessage.Text    = message.Body;
            myMessage.Html    = message.Body;

            var credentials = new NetworkCredential(
                ConfigurationManager.AppSettings["EmailService:Account"],
                ConfigurationManager.AppSettings["EmailService:Password"]);

            // Create a Web transport for sending email.
            var transportWeb = new Web(credentials);

            // Send the email.
            await transportWeb.DeliverAsync(myMessage);
        }
Exemple #19
0
        public async Task SendReplyAsync(string email, string subject, string message)
        {
            var apiKey = "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";
            var client = new SendGridClient(apiKey);
            var msg    = new SendGridMessage()
            {
                From = new EmailAddress("*****@*****.**", "JoaoGomes-Notification"),


                // "*****@*****.**"
                Subject = subject,
                //  PlainTextContent = "Hello, Email!",
                HtmlContent = message
            };

            msg.AddTo(new EmailAddress(email, "email"));

            var response = await client.SendEmailAsync(msg);

            // response.sta
            BackgroundJob.Enqueue(() => Console.WriteLine(response.ToString()));
        }
Exemple #20
0
        public Task Execute(string apiKey, string subject, string message, string email)
        {
            var client = new SendGridClient(apiKey);
            var msg    = new SendGridMessage()
            {
                From             = new EmailAddress("*****@*****.**", "Admin"),
                Subject          = subject,
                PlainTextContent = message,
                HtmlContent      = message
            };

            msg.AddTo(new EmailAddress(email));

            msg.TrackingSettings = new TrackingSettings
            {
                ClickTracking = new ClickTracking {
                    Enable = false
                }
            };

            return(client.SendEmailAsync(msg));
        }
Exemple #21
0
        static async Task Execute(string EmailTo, string Subject, String TemplateID, Object JSON)
        {
            string EmailFrom = "*****@*****.**";

            if (TemplateID == "d-ab773db0353244839c258a59458cd28c" || TemplateID == "d-4590bd4958fa42ca8eb57506e671f368")
            {
                EmailFrom = "*****@*****.**";
            }

            var apiKey = "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";
            var client = new SendGridClient(apiKey);
            var msg    = new SendGridMessage();

            msg.SetFrom(new EmailAddress(EmailFrom, "موقع قيم دكتوري"));
            msg.AddTo(new EmailAddress(EmailTo, Subject));
            msg.SetTemplateId(TemplateID);
            if (JSON != null)
            {
                msg.SetTemplateData(JSON);
            }
            var response = await client.SendEmailAsync(msg);
        }
        public async Task <IActionResult> SendEmail()
        {
            var client = new SendGridClient("");
            var msg    = new SendGridMessage()
            {
                From = new EmailAddress("*****@*****.**",
                                        "Administrator"),
                Subject          = "Informasi",
                PlainTextContent = "Kirim email konfirmasi",
                HtmlContent      = "Kirim email konfirmasi"
            };

            msg.AddTo(new EmailAddress("*****@*****.**"));

            // Disable click tracking.
            // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html
            msg.SetClickTracking(false, false);

            await client.SendEmailAsync(msg);

            return(Content("Kirim email"));
        }
        /// <summary>
        /// Sends templated email with info aboutt changed permissions and email of changer
        /// </summary>
        /// <param name="email">Email who changed permissions</param>
        /// <param name="user">User info</param>
        /// <returns>Response from SendGrid</returns>
        public async Task <HttpStatusCode> SendPermissionsChangedEmailAsync(string email, User user)
        {
            var client = new SendGridClient(_apiKey);
            var msg    = new SendGridMessage();

            msg.From       = new EmailAddress(_fromEmail);
            msg.ReplyTo    = new EmailAddress(_replyEmail);
            msg.TemplateId = _userPermissionsInfoTemplateId;
            msg.SetTemplateData(new
            {
                name      = user.Name,
                surname   = user.Surname,
                email     = user.Email,
                changedBy = email,
                claims    = user.Claims != null && user.Claims.Length > 0 ? string.Join(", ", user.Claims) : "none",
            });
            msg.AddTo(new EmailAddress(user.Email));

            var response = await client.SendEmailAsync(msg);

            return(response.StatusCode);
        }
        public async Task SendEmailAsync(MailMessage message)
        {
            var sendGridMessage = new SendGridMessage
            {
                Subject          = message.Subject,
                From             = new EmailAddress(_globalSettings.Mail.ReplyToEmail, _globalSettings.SiteName),
                HtmlContent      = message.HtmlContent,
                PlainTextContent = message.TextContent,
            };

            sendGridMessage.AddTos(message.ToEmails.Select(e => new EmailAddress(e)).ToList());

            if (message.MetaData?.ContainsKey("SendGridTemplateId") ?? false)
            {
                sendGridMessage.HtmlContent      = " ";
                sendGridMessage.PlainTextContent = " ";
                sendGridMessage.TemplateId       = message.MetaData["SendGridTemplateId"].ToString();
            }

            if (message.MetaData?.ContainsKey("SendGridSubstitutions") ?? false)
            {
                var subs = message.MetaData["SendGridSubstitutions"] as Dictionary <string, string>;
                sendGridMessage.AddSubstitutions(subs);
            }

            if (message.MetaData?.ContainsKey("SendGridCategories") ?? false)
            {
                var cats = message.MetaData["SendGridCategories"] as List <string>;
                sendGridMessage.AddCategories(cats);
            }

            if (message.MetaData?.ContainsKey("SendGridBypassListManagement") ?? false)
            {
                var bypass = message.MetaData["SendGridBypassListManagement"] as bool?;
                sendGridMessage.SetBypassListManagement(bypass.GetValueOrDefault(false));
            }

            await _client.SendEmailAsync(sendGridMessage);
        }
Exemple #25
0
        public async Task Send(string to, string subject, string body)
        {
            to.NotNullOrEmpty(nameof(to));
            subject.NotNullOrEmpty(nameof(subject));
            body.NotNullOrEmpty(nameof(body));

            var client = CreateClient();
            var msg    = new SendGridMessage
            {
                From        = CreateEmailAddress(_emailConfiguration.From.Address),
                Subject     = subject,
                HtmlContent = body,
            };

            msg.AddTo(CreateEmailAddress(to));
            var response = await client.SendEmailAsync(msg).ConfigureAwait(false);

            if (response.StatusCode != HttpStatusCode.Accepted)
            {
                _logger.LogInformation(response.ToString());
            }
        }
Exemple #26
0
        public static SendGridMessage GenerateAlertEmailMessage(ExecutionContext context, EmailFormatModel messageInfo)
        {
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress(EmailFrom, EmailFromMessage));
            msg.AddTos(messageInfo.Recipients.Select(email => new EmailAddress(email)).ToList());

            if (!string.IsNullOrEmpty(messageInfo.Subject))
            {
                msg.SetSubject($"{EmailSubjectPrefix}: {messageInfo.Subject}");
            }
            else
            {
                msg.SetSubject(EmailSubjectPrefix);
            }

            Func <IDictionary <string, object>, string> template;

            string templateFilePath = Path.Combine(context.FunctionAppDirectory, "Files", "AlertEmail.html");

            using (Stream stream = File.OpenRead(templateFilePath))
                using (StreamReader reader = new StreamReader(stream))
                {
                    template = Mustachio.Parser.Parse(reader.ReadToEnd());
                }

            // Set the model with the necessary template format values
            dynamic model = new ExpandoObject();

            model.DeviceId    = messageInfo.DeviceId;
            model.Description = messageInfo.Description;
            model.Severity    = messageInfo.Severity;
            model.Time        = messageInfo.Time;
            model.Notes       = messageInfo.Notes;

            msg.AddContent(MimeType.Html, template(model));

            return(msg);
        }
Exemple #27
0
        private async Task SendAccountValidationEmail(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.From    = new EmailAddress("*****@*****.**", "Admin");
            myMessage.Subject = message.Subject;
            myMessage.AddTo(new EmailAddress(message.Destination, message.Destination));
            myMessage.HtmlContent = message.Body;

            var client = new SendGridClient(System.Configuration.ConfigurationManager.AppSettings["APIKey"]);

            // Send the email.
            if (client != null)
            {
                await client.SendEmailAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
Exemple #28
0
        private async static Task SendGridErrorEmail(string errorMessage, string exMsg,
                                                     List <SendGrid.Helpers.Mail.EmailAddress> recipients)
        {
            string emailTemplate = $@"D:\home\site\wwwroot\{functionName}\Application\Resources\alert_template.html";

            string text = System.IO.File.ReadAllText(emailTemplate);

            text = text.Replace("961b80fb-40bb-4eee-bb61-1f03a4a01668", errorMessage);
            text = text.Replace("e01cce6a-1306-426d-805b-fd024210f027", exMsg);
            System.IO.File.WriteAllText(emailTemplate, text);
            StreamReader reader = System.IO.File.OpenText(emailTemplate);

            var client = new SendGridClient(sendGridKey);
            var msg    = new SendGridMessage()
            {
                From        = new SendGrid.Helpers.Mail.EmailAddress("*****@*****.**", "RBAC Automation"),
                Subject     = "ERROR: RBAC Automation Error Reporting",
                HtmlContent = reader.ReadToEnd()
            };

            msg.AddTos(recipients);

            Console.WriteLine("Email sending");

            try
            {
                var response = await client.SendEmailAsync(msg);
            }
            catch (ArgumentException ex)
            {
                string errorMsg = "Failed to send email for error message.";
                Console.WriteLine(errorMsg);
                Console.WriteLine(errorMessage);
                Console.WriteLine(exMsg);
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Email sent");
        }
Exemple #29
0
        public Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            var client = new SendGridClient(Option.SendGridKey);
            var msg    = new SendGridMessage()
            {
                From             = new EmailAddress("*****@*****.**", "Inventory Management System-Empite"),
                Subject          = subject,
                PlainTextContent = htmlMessage,
                HtmlContent      = htmlMessage
            };

            msg.AddTo(new EmailAddress(email));

            try
            {
                return(client.SendEmailAsync(msg));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Exemple #30
0
        /// <summary>
        /// creates a and sends a email based on the model passed.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static async Task SendEmailWithGrid(EmailModel e)
        {
            SendGridMessage msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress($"{e.SendersEmail}", $"{e.FirstName}, {e.LastName}"));

            var recipients = new EmailAddress("*****@*****.**", "Hanna Myers");

            //hannamyers @hotmail.com

            msg.AddTo(recipients);

            msg.SetSubject("RSVP");

            msg.PlainTextContent = e.Message;

            var apiKey = System.Configuration.ConfigurationManager.AppSettings.Get("sendGridKey");
            var client = new SendGridClient(apiKey);


            await client.SendEmailAsync(msg);
        }
Exemple #31
0
        private async static Task SendGridNewGroupRolesEmail(List <string> groupList,
                                                             List <SendGrid.Helpers.Mail.EmailAddress> recipients)
        {
            if (groupList.Any())
            {
                string emailTemplate = $@"D:\home\site\wwwroot\{functionName}\Application\Resources\newgrouprole_template.html";

                string text   = System.IO.File.ReadAllText(emailTemplate);
                string groups = CreateGroupText(groupList);
                text = text.Replace("961b80fb-40bb-4eee-bb61-1f03a4a01668", groups);
                System.IO.File.WriteAllText(emailTemplate, text);

                StreamReader reader = System.IO.File.OpenText(emailTemplate);

                var client = new SendGridClient(sendGridKey);
                var msg    = new SendGridMessage()
                {
                    From        = new SendGrid.Helpers.Mail.EmailAddress("EMAIL_ADDRESS_HERE", "RBAC Automation"),
                    Subject     = "RBAC Automation New Roles Assigned",
                    HtmlContent = reader.ReadToEnd()
                };
                msg.AddTos(recipients);

                Console.WriteLine("Email sending");

                try
                {
                    var response = await client.SendEmailAsync(msg);
                }
                catch (ArgumentException ex)
                {
                    string errorMsg = "Failed to send email for new roles.";
                    string exMsg    = ex.Message;
                    await ErrorHandling.ErrorEvent(errorMsg, exMsg);
                }

                Console.WriteLine("Email sent");
            }
        }
Exemple #32
0
        bool SendEmail(string userEmail, string body, string firstName, string lastName, string subject)
        {
            string strFromMail = ConfigurationManager.AppSettings["SupportEmail"].ToString();

            try
            {
                //MailAddress mailAddr = new MailAddress(strFromMail,"");
                var msg = new SendGridMessage();
                msg.From = new EmailAddress(strFromMail, "");
                msg.AddTo(userEmail);
                msg.Subject = subject;
                msg.Html    = body;
                var credentials  = new NetworkCredential("*****@*****.**", "2IvC#^kHkCJj");
                var transportWeb = new SendGrid.Web(credentials);
                transportWeb.DeliverAsync(msg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
Exemple #33
0
        public SendNotificationResult SendNotification(Notification notification)
        {
            var retVal = new SendNotificationResult();

            var mail = new SendGridMessage();

            mail.From    = new MailAddress(notification.Sender);
            mail.ReplyTo = new[] { mail.From };
            mail.AddTo(notification.Recipient);
            mail.Subject = notification.Subject;
            mail.Html    = notification.Body;

            var userName = _settingsManager.GetSettingByName(_sendGridUserNameSettingName).Value;
            var password = _settingsManager.GetSettingByName(_sendGridPasswordSettingName).Value;

            var credentials  = new NetworkCredential(userName, password);
            var transportWeb = new Web(credentials);

            try
            {
                Task.Run(async() => await transportWeb.DeliverAsync(mail)).Wait();
                retVal.IsSuccess = true;
            }
            catch (Exception ex)
            {
                retVal.ErrorMessage = ex.Message;

                var invalidApiRequestException = ex.InnerException as InvalidApiRequestException;
                if (invalidApiRequestException != null)
                {
                    if (invalidApiRequestException.Errors != null && invalidApiRequestException.Errors.Length > 0)
                    {
                        retVal.ErrorMessage = string.Join(" ", invalidApiRequestException.Errors);
                    }
                }
            }

            return(retVal);
        }
        public ActionResult<string> SendMail(string to, string link)
        {

            var apiKey = Configuration["API:RegisterAPI"];
            var client = new SendGridClient(apiKey);
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress(Configuration["Email:FromAddress"], "Linkview Registration"));
            List<EmailAddress> eAddress = new List<EmailAddress>();
            if (!string.IsNullOrEmpty(to))
            {
                eAddress.Add(new EmailAddress(to));
            }


            msg.AddTos(eAddress);
            msg.SetSubject("LinkView Registration");
            msg.AddContent(MimeType.Html, link);
            Task t = client.SendEmailAsync(msg);
            t.Wait();
            return "Success";
        }
        public void EmbedImage()
        {
            var client = new SendGridClient(ConfigurationManager.AppSettings["ApiKey"]);

            var message = new SendGridMessage();

            message.To.Add(ConfigurationManager.AppSettings["MailTo"]);
            message.From = ConfigurationManager.AppSettings["MailFrom"];

            message.Subject = "file attachment";
            message.Html = "file attachment test<br /><img src=\"cid:hogehoge\" /><br />inline image";

            message.AddAttachment(ConfigurationManager.AppSettings["AttachmentImage"], "maki.jpg");
            message.Content.Add("maki.jpg", "hogehoge");

            client.Send(message);
        }
        public void Attachment()
        {
            var client = new SendGridClient(ConfigurationManager.AppSettings["ApiKey"]);

            var message = new SendGridMessage();

            message.To.Add(ConfigurationManager.AppSettings["MailTo"]);
            message.From = ConfigurationManager.AppSettings["MailFrom"];

            message.Subject = "file attachment";
            message.Text = "file attachment test";

            message.AddAttachment(ConfigurationManager.AppSettings["AttachmentImage"]);

            client.Send(message);
        }
        public void TemplateEngine()
        {
            var client = new SendGridClient(ConfigurationManager.AppSettings["ApiKey"]);

            var message = new SendGridMessage();

            message.To.Add(ConfigurationManager.AppSettings["MailTo"]);
            message.From = ConfigurationManager.AppSettings["MailFrom"];

            message.Subject = " ";
            message.Text = " ";

            message.UseTemplateEngine("91ba5fd7-984c-4810-95fd-030be7242106");

            message.Header.AddSubstitution("-name-", "抱かれたい男 No.1");
            message.Header.AddSubstitution("-url-", "http://buchizo.wordpress.com/");

            client.Send(message);
        }