public async Task<ProviderProcessResult> Process(Message message)
        {
            try
            {
                var msg = new SendGridMessage();
                msg.AddTo(message.To);
                msg.From = new MailAddress(message.Application.EmailFromAddress, message.Application.EmailFromFullName);
                msg.Subject = message.Subject;
                msg.Html = message.Content;

                var transportWeb = new Web(ConfigurationManager.AppSettings["SendGridSecretKey"]);

                await transportWeb.DeliverAsync(msg);

                return new ProviderProcessResult { IsSuccess = true };
            }
            catch (Exceptions.InvalidApiRequestException ex)
            {
                return new ProviderProcessResult { IsSuccess = false, ErrorMessage = String.Join(",", ex.Errors), ErrorDetails = ex.ToString() };
            }
            catch (Exception ex)
            {
                return new ProviderProcessResult { IsSuccess = false, ErrorMessage = ex.Message, ErrorDetails = ex.ToString() };
            }
        }
        //public ActionResult postServiceRequest()
        //{

        //    var myMessage = new SendGrid.SendGridMessage();
        //    var contractors = db.Contractors.ToList();
        //    var servicerequests = db.ServiceRequests.ToList();
        //string name = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\name.txt");
        //string pass = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\password.txt");
        //    List<String> recipients = new List<String> { };

        //    foreach (var i in contractors)
        //    {

        //        recipients.Add(i.email);

        //    };

        //    foreach (var i in servicerequests)
        //    {
        //        if(i.posted == false)
        //        {
        //            myMessage.AddTo(recipients);
        //            myMessage.From = new MailAddress("*****@*****.**", "Admin");
        //            myMessage.Subject = "New Service Request Posting!!";
        //            string url = "http://*****:*****@"C:\Users\erick\Desktop\Credentials\name.txt");
            string        pass            = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\password.txt");
            var           contractors     = db.Contractors.ToList();
            var           homeowners      = db.Homeowners.ToList();
            var           servicerequests = db.ServiceRequests.ToList();
            List <String> recipients      = new List <String> {
            };
            string identity = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (identity == null)
            {
                return(RedirectToAction("Post_must_be_logged", "Email"));
            }

            var person = db.Homeowners.Where(x => x.UserId == identity).SingleOrDefault();

            foreach (var i in contractors)
            {
                recipients.Add(i.email);
            }
            ;

            foreach (var user in db.Users)
            {
                if (user.Id == identity)
                {
                    foreach (var i in servicerequests)
                    {
                        if (id == i.ID)
                        {
                            if (i.posted == false)
                            {
                                myMessage.AddTo(recipients);
                                myMessage.From    = new MailAddress("*****@*****.**", "Admin");
                                myMessage.Subject = "New Service Request Posting!!";
                                string url     = "http://localhost:14703/ServiceRequests/ContractorAcceptance/" + i.ID;
                                string message = "Job Location: <br>" + i.Address + "<br>" + i.City + "<br>" + i.State + "<br>" + i.Zip + "<br>" + "<br>" + "Job Description: <br>" + i.Description + "<br>" + "<br>" + "Bid price: <br>$" + i.Bid + "<br>" + "<br>" + "Must be completed by: <br>" + i.CompletionDeadline + "<br>" + "<br>" + "Date Posted: <br>" + i.PostedDate + "<br>" + "<br>" + "To accept job, click on link below: <br><a href =" + url + "> Click Here </a>";
                                myMessage.Html = message;
                                var credentials  = new NetworkCredential(name, pass);
                                var transportWeb = new SendGrid.Web(credentials);
                                transportWeb.DeliverAsync(myMessage);
                                i.posted        = true;
                                i.ServiceNumber = i.ID;
                                i.Confirmed     = false;
                            }

                            else
                            {
                                return(RedirectToAction("DuplicatePost", "ServiceRequests"));
                            }
                        }
                    }
                }
            }
            db.SaveChanges();
            return(RedirectToAction("About", "Home"));
        }
        // POST: api/RequestData
        public HttpResponseMessage Post([FromBody]RequestData value)
        {
            try
            {
                // Create the email object first, then add the properties.
                SendGridMessage myMessage = new SendGridMessage();
                myMessage.AddTo("*****@*****.**");
                myMessage.From = new MailAddress("*****@*****.**");
                myMessage.Subject = string.Format("Message from DRB Technology");
                myMessage.Text = string.Format("From: {0} {1} \n Message: {2}", value.email, value.yourName, value.yourRequest);

                // Create credentials, specifying your user name and password.
                //TODO: Set credentials
                var credentials = new NetworkCredential("", "");

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

                // ...OR create a Web transport, using API Key (preferred)
                //var transportWeb = new Web("This string is an API key");

                // Send the email.
                transportWeb.DeliverAsync(myMessage);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException);
            }

            return Request.CreateResponse(HttpStatusCode.OK, "Thank you for your request. We aim to respond within 24 hours.");
        }
        public ActionResult sendMailNow()///(string message)
        {
            db = new ApplicationDbContext();
            var    myMessage = new SendGrid.SendGridMessage();
            string name      = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\name.txt");
            string pass      = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\password.txt");

            List <String> recipients = new List <String> {
            };

            //{
            //@"Changa Chimp <*****@*****.**>",
            //@"Penny Wise <*****@*****.**>",
            //@"E. Matts <*****@*****.**>",
            //};

            foreach (var i in db.Homeowners)
            {
                recipients.Add(i.email);
            }
            ;

            myMessage.AddTo(recipients);
            myMessage.From    = new MailAddress("*****@*****.**", "Joe Johnson");
            myMessage.Subject = "Sending with SendGrid is Fun";
            //myMessage.Html = "<p>Hello World!</p>";
            myMessage.Text = "Welcome to Work Warriors";
            var credentials  = new NetworkCredential(name, pass);
            var transportWeb = new SendGrid.Web(credentials);

            transportWeb.DeliverAsync(myMessage);

            return(RedirectToAction("About", "Home"));
        }
        private async Task SendRestorePasswordEmail(string requestId, ApplicationUser user)
        {
            var url = Url.Action("SetNewPassword", "RestorePassword", new { requestId }, "https");

            var message = new SendGridMessage();

            message.AddTo(user.Email);
            message.From    = new MailAddress("*****@*****.**", "Добрый робот uLearn");
            message.Subject = "Восстановление пароля uLearn";
            message.Html    = "Чтобы изменить пароль к аккаунту " + user.UserName + ", перейдите по ссылке: <a href=\"" + url + "\">" + url + "</a>";

            var login       = ConfigurationManager.AppSettings["SendGrid.Login"];
            var password    = ConfigurationManager.AppSettings["SendGrid.Password"];
            var credentials = new NetworkCredential(login, password);

            var transport = new SendGrid.Web(credentials);

            try
            {
                await transport.DeliverAsync(message);
            }
            catch (InvalidApiRequestException ex)
            {
                throw new Exception(ex.Message + ":\n\n" + string.Join("\n", ex.Errors), ex);
            }
        }
Exemple #6
0
        public Task GetTransportWebAsync(MailMessageBody body)
        {
            var msg = new SendGridMessage();

            msg.AddTo(_to.Address);
            msg.From    = _from;
            msg.Subject = _subject;
            msg.Text    = body.ToString();
            msg.Html    = body.ToString();

            var credentials = new NetworkCredential(GetMailAccount(), GetMailPassword());

            // create a Web transport for sending mail
            var transportWeb = new SendGrid.Web(credentials);

            // return the web transport
            if (transportWeb != null)
            {
                return(transportWeb.DeliverAsync(msg));
            }
            else
            {
                return(Task.FromResult(0));
            }
        }
Exemple #7
0
        public async void SendPasswordReset(string email)
        {
            // Create the email object first, then add the properties.
            SendGridMessage myMessage = new SendGridMessage();

            // Add the message properties.
            myMessage.From = new MailAddress("*****@*****.**", "Chris Pena");
            string recipient = email;

            myMessage.AddTo(recipient);
            myMessage.Subject = "Testing the SendGrid Library";

            //Add the HTML and Text bodies
            myMessage.Html = GetMessageBody(email);
            myMessage.Text = "Hello World plain text!";
            //myMessage.AddAttachment(@"C:\file1.txt");

            // Create credentials, specifying your user name and password.
            NetworkCredential credentials = new NetworkCredential("udmschrispena", "1q0p2w9o");

            // Create an Web transport for sending email.
            SendGrid.Web transportWeb = new SendGrid.Web("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");

            // Send the email.
            // You can also use the **DeliverAsync** method, which returns an awaitable task.
            await transportWeb.DeliverAsync(myMessage);
        }
Exemple #8
0
        public static void Send(List <string> recipients, string subject, string messageBody)
        {
            var myMessage = new SendGridMessage();

            var fromAddress = (SettingHelper.Get(EMAIL_FROM_ADDRESS));

            if (string.IsNullOrEmpty(fromAddress))
            {
                return;
            }

            myMessage.From = new MailAddress(fromAddress);

            myMessage.AddTo(recipients);

            myMessage.Subject = $"{SettingHelper.Get(WEBSITE_NAME)}: {subject}";
            myMessage.Html    = messageBody;

            myMessage.EnableClickTracking();

            var username = SettingHelper.Get(SENDGRID_USERNAME);
            var password = SettingHelper.Get(SENDGRID_PASSWORD);

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return;
            }

            var credentials = new NetworkCredential(username, password);

            var transportWeb = new SendGrid.Web(credentials);

            transportWeb.DeliverAsync(myMessage);
        }
Exemple #9
0
        public static void Send(string sender, string[] tolist, string[] ccList, string[] bccList, string subject, string body, bool iSJob = false)
        {
            try
            {
                var message = new SendGridMessage
                {
                    From = new MailAddress(Utils.GetSetting(MAIL_SENDER, ""), Utils.GetSetting(MAIL_USER, ""), Encoding.UTF8)
                };

                message.AddTo(tolist);
                message.AddCc(ccList);
                message.AddBcc(bccList);
                message.Subject = subject;
                message.Html    = body;

                //var credentials = new NetworkCredential("ssp_system_admin", "Asdcvnmmvb");
                var credentials = new NetworkCredential(Utils.GetSetting(MAIL_USER, "ssp_system_admin"), Utils.GetSetting(MAIL_PASSWORD, "Asdcvnmmvb"));
                // Create a Web transport for sending email.
                var transportWeb = new SendGrid.Web(credentials);
                if (iSJob)
                {
                    transportWeb.DeliverAsync(message).Wait();
                }
                else
                {
                    transportWeb.DeliverAsync(message);
                }
            }
            catch (Exception ex)
            {
            }
        }
        private Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                "*****@*****.**", "Admin");
            myMessage.Subject = message.Subject;
            myMessage.Text    = message.Body;
            myMessage.Html    = message.Body;

            var credentials = new NetworkCredential(
                ConfigurationManager.AppSettings["mailAccount"],
                ConfigurationManager.AppSettings["mailPassword"]
                );

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

            // Send the email.
            if (transportWeb != null)
            {
                return(transportWeb.DeliverAsync(myMessage));
            }
            else
            {
                return(Task.FromResult(0));
            }
        }
Exemple #11
0
            public async Task EmailCanSendTestDirect()
            {
                // Arrange

                // Act

                // Send direct, bypass grain
                var transport = new SendGrid.Web(new NetworkCredential(_sendgridApiUsername, _sendgridApiPassword));

                try
                {
                    _testSendGridMessage.Subject = "(CanSendTestEmailDirect) Test message";

                    Task  t = transport.DeliverAsync(_testSendGridMessage);
                    await t;

                    if (t.Exception != null)
                    {
                        throw new ApplicationException(t.Exception.Message, t.Exception);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
                return;
            }
        public async Task <string> SendQuoteSurvey(PolicyDTO policy)
        {
            string batchId = await GetBatchId();

            string fullName = $"{policy.Contact.FirstName} {policy.Contact.LastName}";

            SendGridMessage message = new SendGridMessage()
            {
                To      = new MailAddress[] { new MailAddress(policy.Contact.EmailAddress, fullName), },
                Subject = "RAC Bicycle Insurance Survey",
                From    = new MailAddress(ExternalEmailsFrom, "RAC Bicycle Insurance"),
                Html    = $"Hi",
                Text    = $"Hi"
            };

            message.Headers["batch_id"] = batchId;
            message.SetSendAt(DateTime.UtcNow.AddMinutes(10));
            message.EnableTemplateEngine(_surveyTemplateId);
            message.AddSubstitution("%%name%%", new List <string> {
                fullName
            });

            SendGrid.Web transportWeb = new SendGrid.Web(_sendGridApiKey);

            await transportWeb.DeliverAsync(message);

            return("Hello");
        }
        // Implementação do SendGrid
        private Task ConfigSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(message.Destination);
            myMessage.From = new MailAddress("*****@*****.**", "Admin do Portal");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["mailAccount"], ConfigurationManager.AppSettings["mailPassword"]);

            // Criar um transport web para envio de e-mail
            var transportWeb = new Web(credentials);

            // Enviar o e-mail
            if (transportWeb != null)
            {
                var x = transportWeb.DeliverAsync(myMessage);
                return x;
            }
            else
            {
                return Task.FromResult(0);
            }
        }
Exemple #14
0
        public static void Send(List <string> recipients, string subject, string messageBody)
        {
            var myMessage = new SendGridMessage();

            var fromAddress = (SettingHelper.Get("Email From Address"));

            if (string.IsNullOrEmpty(fromAddress))
            {
                return;
            }

            myMessage.From = new MailAddress(fromAddress);

            myMessage.AddTo(recipients);

            myMessage.Subject = string.Format("{0}: {1}", SettingHelper.Get("Website Name"), subject);
            myMessage.Html    = messageBody;

            myMessage.EnableClickTracking();

            var username = SettingHelper.Get("SendGrid UserName");
            var password = SettingHelper.Get("SendGrid Password");

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return;
            }

            var credentials = new NetworkCredential(username, password);

            var transportWeb = new SendGrid.Web(credentials);

            transportWeb.DeliverAsync(myMessage);
        }
        // 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 MailAddress(this.fromAddress, "NinjaHive System");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

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

            // Send the email.
            try
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            //http://stackoverflow.com/questions/28878924/bad-request-check-errors-for-a-list-of-errors-returned-by-the-api-at-sendgrid
            catch (InvalidApiRequestException ex)
            {
                var errorDetails = new StringBuilder();

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

                throw new ApplicationException(errorDetails.ToString(), ex);
            }
        }
        public async Task SendEmailAsync( string destination, string subject, string body )
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                ConfigurationManager.AppSettings["emailService:FromAddress"],
                ConfigurationManager.AppSettings["emailService:FromName"]);
            myMessage.Subject = subject;
            myMessage.Text = body;
            myMessage.Html = 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.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
        protected void Submit_Click(object sender, EventArgs e)
        {
            String contact = "";

            if (!string.IsNullOrWhiteSpace(mobile.Text))
                contact = "Contact number: " + mobile.Text;

            // SendGrid credentials
            var credentials = new NetworkCredential(
                ConfigurationManager.AppSettings["SendGridUserId"],
                ConfigurationManager.AppSettings["SendGridPassword"]);

            // Create the email object first, then add the properties.
            SendGridMessage myMessage = new SendGridMessage();
            myMessage.AddTo("*****@*****.**");
            myMessage.From = new MailAddress(email.Text, name.Text);
            myMessage.Subject = "Feedback: " + subject.Text;

            myMessage.Html = contact + "<p>" + message.Text + "</p>";

            // Create an Web transport for sending email, using credential
            var transportWeb = new Web(credentials);

            // Send the email.
            transportWeb.DeliverAsync(myMessage);

            email.Text = "";
            name.Text = "";
            mobile.Text = "";
            subject.Text = "";
            message.Text = "";
        }
Exemple #18
0
        private async Task FeedbackEmailAsync(FeedbackViewModel message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo("*****@*****.**");
            myMessage.From = new System.Net.Mail.MailAddress(message.Email, message.Name);
            myMessage.Subject = message.Subject;
            myMessage.Html = message.Message;

            var transportWeb = new Web("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");

            try
            {
                if (transportWeb != null)
                {
                    await transportWeb.DeliverAsync(myMessage);
                }
                else
                {
                    await Task.FromResult(0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #19
0
        private async Task ConfigSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress("*****@*****.**", "Система за гласуване.");
            myMessage.Subject = message.Subject;
            myMessage.Html = message.Body;

            var transportWeb = new Web("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");
            try
            {
                if (transportWeb != null)
                {
                    await transportWeb.DeliverAsync(myMessage);
                }
                else
                {
                    await Task.FromResult(0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #20
0
 private void sendEmails(Dictionary<string, string> users)
 {
     if (users.Count < 1)
     {
         return;
     }
     var credentials = new NetworkCredential("*****@*****.**", "qYzcc6C3Z1A7TB2");
     var transportWeb = new Web(credentials);
     var myMessage = new SendGridMessage();
     myMessage.From = new MailAddress("*****@*****.**", "ExpInfo team");
     myMessage.Text = "Happy Birthday! Thanks for using our servises!";
     foreach (var user in users)
     {
         try
         {
             myMessage.AddTo(user.Value);
             myMessage.Subject = string.Format("Hello, {0}!", user.Key);
             // Send the email.
             transportWeb.Deliver(myMessage);
         }
         catch (Exception)
         {
         }
     }
 }
        public ActionResult sendContractorMail()
        {
            db = new ApplicationDbContext();
            var    myMessage = new SendGrid.SendGridMessage();
            string name      = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\name.txt");
            string pass      = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\password.txt");

            List <String> recipients = new List <String> {
            };

            foreach (var i in db.Contractors)
            {
                recipients.Add(i.email);
            }
            ;

            myMessage.AddTo(recipients);
            myMessage.From    = new MailAddress("*****@*****.**", "Joe Johnson");
            myMessage.Subject = "New Service Request Posting!!";
            myMessage.Text    = "Service request:";
            var credentials  = new NetworkCredential(name, pass);
            var transportWeb = new SendGrid.Web(credentials);

            transportWeb.DeliverAsync(myMessage);

            return(RedirectToAction("About", "Home"));
        }
Exemple #22
0
        private async Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                "*****@*****.**", "Swetugg");
            myMessage.Subject = message.Subject;
            myMessage.Text    = message.Body;
            myMessage.Html    = message.Body;

            var credentials = new NetworkCredential(
                ConfigurationManager.AppSettings["SendGrid_Messaging_MailAccount"],
                ConfigurationManager.AppSettings["SendGrid_Messaging_MailPassword"]
                );

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

            // Send the email.
            try
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            catch (Exception)
            {
                //
            }
        }
        /*
        static string smtpAddress = "smtp.gmail.com";
        static int portNumber = 587;
        static bool enableSSL = true;
        static string emailFrom = "*****@*****.**";
        static string password = "******";
        //string emailTo = "*****@*****.**";
        static string subject = "";
        static string body = "";
        static string org;
        //*/
        /*
        public static void enviarAlerta(string emailTo, string subject,string body)
        {
            try
            {                

                using (MailMessage mail = new MailMessage())
                {
                    mail.From = new MailAddress(emailFrom);
                    mail.To.Add(emailTo);
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.IsBodyHtml = true;
                    // Can set to false, if you are sending pure text.

                    using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                    {
                        smtp.Credentials = new NetworkCredential(emailFrom, password);
                        smtp.EnableSsl = enableSSL;
                        smtp.Send(mail);
                    }
                }
            }
            catch
            {
                
            }
        }
        //*/

        public static void enviarAlerta(List<string> emailTo, string subject, string body) 
        {
            // Add multiple addresses to the To field.
            List<String> recipients = emailTo;

            var username = System.Environment.GetEnvironmentVariable("SENDGRID_USERNAME");
            var pswd = System.Environment.GetEnvironmentVariable("SENDGRID_PASSWORD");

            // Create the email object first, then add the properties.
            SendGridMessage myMessage = new SendGridMessage();
            myMessage.AddTo(recipients);
            myMessage.From = new MailAddress("*****@*****.**", "Sistema de avisos Renta-Maq");
            myMessage.Subject = subject;
            myMessage.Html= body;

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

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

            // Send the email, which returns an awaitable task.
            transportWeb.DeliverAsync(myMessage);

            // If developing a Console Application, use the following
            // transportWeb.DeliverAsync(mail).Wait();
        }
Exemple #24
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(
                                "*****@*****.**", "LaFactureria");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(
                       ConfigurationManager.AppSettings["mailAccount"],
                       ConfigurationManager.AppSettings["mailPassword"]
                       );

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

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                Trace.TraceError("Fallo al crear el transporte Web y no se fue posible enviar el correo.");
                await Task.FromResult(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("*****@*****.**", "Gada");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["sgUsername"],
                                                    ConfigurationManager.AppSettings["sgPassword"]);

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

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
        private async Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                "*****@*****.**", "Do not reply");
            myMessage.Subject = message.Subject;
            myMessage.Text    = message.Body;
            myMessage.Html    = message.Body;

            var credentials = new NetworkCredential(
                ConfigurationManager.AppSettings["mailAccount"],
                ConfigurationManager.AppSettings["mailPassword"]
                );

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

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
Exemple #27
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 MailAddress(
                AppSettingsService.NoReplyEmail,
                AppSettingsService.NoReplyFullname);
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(
                AppSettingsService.EmailServiceAccount,
                AppSettingsService.EmailServicePassword);

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

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
        private async Task<string> SendEmail(string emailTo, string emailFrom, string fromUserId,
            string toUserName, string inviteCode)
        {
            var fromUserName = db.Users.Find(fromUserId).FirstName + " " + db.Users.Find(fromUserId).LastName;
            var Household = db.Users.Find(fromUserId).Household;
            //string url = "http://localhost:59490/"; //Address of the local host; modify as needed.
            string url = "http://budgetmaster1.azurewebsites.net/"; //Set to URL of online application.
            var body = toUserName + " ,\r\r\r" + fromUserName + " has invited you to join the '" +
                    Household + "' Household in Budget Master! Your invitation code is: " + inviteCode +
                    ". Please go to " + url + ", choose 'Register' in the menu, and enter your information, " +
                    "including the invitation code.";

            var appSettings = ConfigurationManager.AppSettings;
            var credentials = new NetworkCredential(appSettings["SendGridUserName"], appSettings["SendGridPassword"]);
            SendGridMessage message = new SendGridMessage();
            message.AddTo(emailTo);
            message.From = new MailAddress(emailFrom, fromUserName);
            message.Subject = "Invitation to Budget Master";
            message.Text = body;
            var transportWeb = new Web(credentials);
            await transportWeb.DeliverAsync(message);
            var result = "An e-mail invitation to the household has been delivered to " + emailTo + ".";

            return result;
        }
        public async  void SendMailNotification(string sharePointAppUrl, string name, string useremail = null)
        {
                string description = $"Sharepoint site '{name}' created.";
                var urlValue = "<a href=" + name + ">" + sharePointAppUrl + "</a>";

                object[] parameters = { description , urlValue };
                var msgBody = GetMailMessage(parameters);

                var mailMessage = new SendGridMessage();

                var mailFrom = WebConfigurationManager.AppSettings["MailFrom"];
                var maintenanceEmailAddress = WebConfigurationManager.AppSettings["MaintenanceEmailAddress"];
                var mailUserName = WebConfigurationManager.AppSettings["MailUserID"];
                var mailPassword = WebConfigurationManager.AppSettings["MailPassword"];

                mailMessage.From = new MailAddress(mailFrom);
                var recipients = new List<string> {maintenanceEmailAddress};

                if (useremail != null)
                {
                    recipients.Add(useremail);
                }

                recipients.Add(mailFrom);
                mailMessage.AddTo(recipients);

                mailMessage.Subject =  description; 
                mailMessage.Html = msgBody;

                var credentials = new NetworkCredential(mailUserName, mailPassword);
                var transportWeb = new Web(credentials);
                await transportWeb.DeliverAsync(mailMessage);
            

        }
Exemple #30
0
        public void SendEmail(MailMessage mail)
        {
            var environment = ConfigurationManager.AppSettings["environment"];

            if (environment == "prod")
            {
                var accountSendGrid  = ConfigurationManager.AppSettings["mailAccountSendGrid"];
                var passwordSendGrid = ConfigurationManager.AppSettings["mailPasswordSenGrid"];
                var credentials      = new NetworkCredential(accountSendGrid, passwordSendGrid);
                var transportWeb     = new SendGrid.Web(credentials);

                SendGridMessage myMessage = new SendGridMessage();
                myMessage.AddTo(mail.To.ToString());
                myMessage.From    = new MailAddress(mail.From.ToString(), "Coordonateur de stages");
                myMessage.Subject = mail.Subject.ToString();
                myMessage.Text    = mail.Body.ToString();

                transportWeb.Deliver(myMessage);
            }
            else
            {
                var client = new SmtpClient("jenkinssmtp.cegep-ste-foy.qc.ca", 25)
                {
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false
                };

                client.Send(mail);
            }
        }
        // POST: api/Email
        public IHttpActionResult Post (Email emailMessage)
        {
           



            var mailMessage = new SendGridMessage();
            mailMessage.AddTo("*****@*****.**");
            try {
                mailMessage.From = new MailAddress(emailMessage.EmailAddress);
            } catch  {
                ModelState.AddModelError("Email", "Invalid Email Address");
            }
            mailMessage.Subject = "Forest Film Contact";
            mailMessage.Text = emailMessage.Message +"\n\nName: " + emailMessage.FirstName + " " + emailMessage.LastName + "\nEmail: " + emailMessage.EmailAddress + "\nPhone: " + emailMessage.Phone;
            var transportWeb = new Web("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");
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(this.ModelState);
                }
                transportWeb.DeliverAsync(mailMessage).Wait();
                return Ok();
            }
            catch {
                ModelState.AddModelError("Error", "There was an error sending your message, please try again soon");
                return BadRequest(this.ModelState);
            }
           

            
        }
        public ActionResult Send([ModelBinder(typeof(MailModelBinder))]MailModel model, string vendore, string redirectUrl)
        {
            var username = ConfigurationManager.AppSettings["SendGridUsername"];
            var password = ConfigurationManager.AppSettings["SendGridPassword"];

            var message = new SendGridMessage();
            message.AddTo(ConfigurationManager.AppSettings["SupportToEmail"]);
            message.From = new MailAddress(model.To, model.FullName);
            message.Subject = model.Subject;
            message.Html = model.FullMailBody;
            var credentials = new NetworkCredential(username, password);
            var transportWeb = new Web(credentials);
            transportWeb.Deliver(message);

            if (!string.IsNullOrEmpty(vendore))
            {
                try
                {
                    message = new SendGridMessage();
                    message.AddTo(vendore.Replace("[", "@"));
                    message.From = new MailAddress(model.To, model.FullName);
                    message.Subject = model.Subject;
                    message.Html = model.FullMailBody;
                    transportWeb.Deliver(message);
                }
                catch
                {

                }
            }

            return Redirect(redirectUrl);
        }
        public bool SendPolicyDetails(PolicyDTO policy)
        {
            SendGridMessage message = new SendGridMessage();

            var subject = "RAC Bicycle Insurance - " + policy.PolicyNumber;
            var body    = CreateCsvFromDto(policy);

            message.To      = AdminEmailsTo.Select(email => new MailAddress(email)).ToArray();
            message.Subject = "RAC Bicycle Insurance - " + policy.PolicyNumber;
            message.From    = new MailAddress(AdminEmailsFrom, "RAC Bicycle Insurance");
            message.ReplyTo = new MailAddress[] { message.From };
            message.Text    = body;

            // Todo complete the zip file implementation
            // ZipFile zipFile = new ZipFile();
            // zipFile.Password = "******";
            // zipFile.AddEntry();


            message.AddAttachment(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(body)), subject + ".csv");

            var transportWeb = new SendGrid.Web(_sendGridApiKey);

            var task = Task.Run(async() =>
            {
                await transportWeb.DeliverAsync(message);
            });

            task.Wait(TimeSpan.FromSeconds(30));


            return(true);
        }
        // Use NuGet to install SendGrid (Basic C# client lib) 
        private async Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            //NEED TO UPDATE THIS TO OUR DETAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! http://bitoftech.net/2015/02/03/asp-net-identity-2-accounts-confirmation-password-user-policy-configuration/
            myMessage.From = new System.Net.Mail.MailAddress("*****@*****.**", "Taiseer Joudeh");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            //NEED TO UPDATE THIS TO OUR DETAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! http://bitoftech.net/2015/02/03/asp-net-identity-2-accounts-confirmation-password-user-policy-configuration/
            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.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
Exemple #35
0
        // Implementação do SendGrid
        private Task ConfigSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From    = new MailAddress("*****@*****.**", "Admin do Portal");
            myMessage.Subject = message.Subject;
            myMessage.Text    = message.Body;
            myMessage.Html    = message.Body;

            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["mailAccount"], ConfigurationManager.AppSettings["mailPassword"]);

            // Criar um transport web para envio de e-mail
            var transportWeb = new SendGrid.Web(credentials);

            // Enviar o e-mail
            if (transportWeb != null)
            {
                var x = transportWeb.DeliverAsync(myMessage);
                return(x);
            }
            else
            {
                return(Task.FromResult(0));
            }
        }
        public async Task<bool> SendMailAsync(MailMessage mm, bool suppressExceptions=true)
        {
            try
            {
                string userName = _configurationService.SendGridUsername;
                string password = _configurationService.SendGridPassword;

                var message = new SendGridMessage();

                message.From = new MailAddress(mm.From);
                message.AddTo(mm.To);
                message.Subject = mm.Subject;
                message.Text = mm.Body;

                var credentials = new NetworkCredential(userName, password);
                var transportWeb = new Web(credentials);
                await transportWeb.DeliverAsync(message).ConfigureAwait(false);

                return true;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                if (!suppressExceptions)
                    throw;
            }

            return false;
        }
Exemple #37
0
        public void Enviar(string nome, string email, string assunto, string mensagem)
        {
            var myMessage = new SendGridMessage();

            myMessage.From = new MailAddress(email, nome);
            myMessage.AddTo("*****@*****.**");
            myMessage.Subject = assunto;
            myMessage.Text = mensagem;

            var username = "******";
            var pswd = "20LTaus55pBSA3m";
            /* Alternatively, you may store these credentials via your Azure portal
               by clicking CONFIGURE and adding the key/value pairs under "app settings".
               Then, you may access them as follows:
               var username = System.Environment.GetEnvironmentVariable("SENDGRID_USER");
               var pswd = System.Environment.GetEnvironmentVariable("SENDGRID_PASS");
               assuming you named your keys SENDGRID_USER and SENDGRID_PASS */

            var credentials = new NetworkCredential(username, pswd);
            var transportWeb = new Web(credentials);

            // Send the email.
            // You can also use the **DeliverAsync** method, which returns an awaitable task.
            transportWeb.DeliverAsync(myMessage);
        }
        // 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(
                PODEnvironment.GetSetting("emailService:GeneralEmail"),
                PODEnvironment.GetSetting("emailService:GeneralEmailName"));
            myMessage.Subject = message.Subject;
            myMessage.Text    = message.Body;
            myMessage.Html    = message.Body;

            var credentials = new NetworkCredential(PODEnvironment.GetSetting("emailService:Account"),
                                                    PODEnvironment.GetSetting("emailService:Password"));

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

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
Exemple #39
0
        private async Task SendGridAsync(IdentityMessage message)
        {
            var sec = (ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection);

            if (sec != null)
            {
                var displayName = sec.From;
                var fromEmailAddress = sec.Network.UserName;
                var passwordEmail = sec.Network.Password;

                var sendMessage = new SendGridMessage()
                {
                    From = new MailAddress(fromEmailAddress, displayName),
                    Subject = message.Subject,
                    Text = message.Body,
                    Html = message.Body
                };
                sendMessage.AddTo(message.Destination);

                var credentials = new NetworkCredential(fromEmailAddress, passwordEmail);
                var transportWeb = new Web(credentials);
                if (transportWeb != null)
                {
                    await transportWeb.DeliverAsync(sendMessage);
                }
                else
                {
                    await Task.FromResult(0);
                }
            }
            else
            {
                await Task.FromResult(0);
            }
        }
        public async Task <ActionResult> BugReport(BugReportViewModel viewModel)
        {
            try
            {
                //SendGrid username and password from azure.
                var username = "******";
                var pswrd    = "27UICbH178dUI0m";
                //Create a new SendGrid message
                var mailMessage = new SendGridMessage();
                //Where the mail has to go to
                mailMessage.AddTo("*****@*****.**");
                //Sender from the mail
                mailMessage.From = new MailAddress(viewModel.EmailAddress);
                //Subject from the mail
                mailMessage.Subject = viewModel.Subject;
                //Body of the mail
                mailMessage.Html = viewModel.Message;
                mailMessage.Html = mailMessage.Html.Replace(Environment.NewLine, "<br />");
                var credentials = new NetworkCredential(username, pswrd);
                //Send the mail using SendGrid
                var transportWeb = new SendGrid.Web(credentials);
                await transportWeb.DeliverAsync(mailMessage);

                return(View());
            }
            catch (Exception ex)
            {
                Response.Write("Could not send the e-mail - error: " + ex.Message);
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }
Exemple #41
0
        private Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                                "*****@*****.**", "Joe S.");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(
                       ConfigurationManager.AppSettings["mailAccount"],
                       ConfigurationManager.AppSettings["mailPassword"]
                       );

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

            // Send the email.
            if (transportWeb != null)
            {
                return transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                return Task.FromResult(0);
            }
        }
Exemple #42
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("*****@*****.**", "Francisco Paz");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            // Create network credentials to access your SendGrid account
            var username = "";
            var pswd = "";

            var credentials = new NetworkCredential(username, pswd);
            
            //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.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
Exemple #43
0
        private async Task SendAsync(ISendGrid message)
        {
            var credentials = new NetworkCredential("Gregorio", "LosAngeles8!");

            var trasportToWeb = new SendGrid.Web(credentials);

            await trasportToWeb.DeliverAsync(message);
        }
Exemple #44
0
        public static void SendEmail(Campaign model, string[] recipients, string sendgridapiKey)
        {
            var message = CreateSendgridMessage(model, recipients);

            var transportWeb = new SendGrid.Web(sendgridapiKey);

            transportWeb.DeliverAsync(message);
        }
Exemple #45
0
        /**
         * This method will create sendgrid web transport object from the credential
         * and send email using DeliverAsync() from Sendgrid api
         * @param SendGrid.SendGridMessage message
         * @return void
         */
        private static void SendAsync(SendGrid.SendGridMessage message)
        {
            // Create a Web transport for sending email.
            var transportWeb = new SendGrid.Web(new NetworkCredential("username", "password"));

            // Send the email.
            transportWeb.DeliverAsync(message);
        }
Exemple #46
0
        private static async Task SendAsync(ISendGrid message)
        {
            var credentials = new NetworkCredential("xyz", "12345!");

            var trasportToWeb = new SendGrid.Web(credentials);

            await trasportToWeb.DeliverAsync(message);
        }
Exemple #47
0
        //sending out referral code with user specific referral codes -Anna
        public void ReferralEmail(Guid Token, string Email)
        {
            SendGridMessage SendReferral = new SendGridMessage();

            SendReferral.AddTo(Email);
            SendReferral.From    = new MailAddress(ConfigService.SupportEmail);
            SendReferral.Subject = "Invitation to try bringpro";
            SendReferral.Text    = "Your friend has invited you to try bringpro. Use their referral code to get 25% off your first order!" + ConfigService.SiteBaseUrl + "/Public/referralRegister/" + Token;

            var transportWeb = new SendGrid.Web(ConfigService.SendGridWebKey);

            transportWeb.DeliverAsync(SendReferral);
        }
Exemple #48
0
        public Task SendMail(string to, string subject, string message)
        {
            SendGridMessage mail = new SendGridMessage();

            mail.From = new MailAddress(this.hostEmail, "Vote On");
            mail.AddTo(to);
            mail.Subject = subject;
            mail.Html    = message;

            var transportWeb = new SendGrid.Web(this.credentials);

            return(transportWeb.DeliverAsync(mail));
        }
Exemple #49
0
        public static void SendPasswordResetEmail(string toEmail, string encodeUserID, string plainUserName)
        {
            try
            {
                var          domain      = HttpContext.Current.Request.Url.Authority;
                StreamReader reader      = new StreamReader(HttpContext.Current.Server.MapPath("/EmailTemplate/PasswordReset.html"));
                string       readFile    = reader.ReadToEnd();
                var          redirectUrl = ConfigurationManager.AppSettings["CurruntURL"].ToString() + "/#/resetPassword/" + encodeUserID;
                string       myString    = "";
                myString = readFile;
                myString = myString.Replace("{USERNAME}", plainUserName);
                myString = myString.Replace("{VERIFICATION_LINK}", redirectUrl);

                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo(toEmail);
                myMessage.From    = new MailAddress("*****@*****.**", "JobsInABA");
                myMessage.Subject = "Forgot Password";
                myMessage.Html    = myString.ToString();

                var transportWeb = new SendGrid.Web("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");
                transportWeb.DeliverAsync(myMessage);

                //// MailMessage class is present is System.Net.Mail namespace
                //MailMessage mailMessage = new MailMessage();
                //var _fromMailAddress = ConfigurationManager.AppSettings["FromMailAddress"].ToString();
                //var _fromMailPassword = ConfigurationManager.AppSettings["FromMailPassword"].ToString();
                //var _fromMailSMTP = ConfigurationManager.AppSettings["FromMailSMTP"].ToString();
                //int _formMailPort = Convert.ToInt32(ConfigurationManager.AppSettings["FromMailPort"]);

                //MailAddress fromMail = new MailAddress(_fromMailAddress);
                //mailMessage.From = fromMail;
                //mailMessage.To.Add(toEmail);
                //mailMessage.IsBodyHtml = true;
                //mailMessage.Body = myString.ToString();
                //mailMessage.Subject = "Forgot Password";

                //SmtpClient smtpClient = new SmtpClient(_fromMailSMTP, _formMailPort);
                //smtpClient.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["IsEnableSSl"].ToString());
                //smtpClient.Credentials = new System.Net.NetworkCredential()
                //{
                //    UserName = _fromMailAddress,
                //    Password = _fromMailPassword
                //};

                //smtpClient.Send(mailMessage);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #50
0
        //sends automated email through Contact Request's email address and rendered HTML string.
        public void sendContactRequestEmail(EmailRequestModel crModel)
        {
            string renderedHTML = EmailService.RenderRazorViewToString("~/Views/TestEmail/Index.cshtml", crModel);

            SendGridMessage ActivateCrEmail = new SendGridMessage();

            ActivateCrEmail.AddTo(crModel.Email);
            ActivateCrEmail.From    = new MailAddress("*****@*****.**");
            ActivateCrEmail.Html    = renderedHTML;
            ActivateCrEmail.Subject = "Your BringPro input has been successfully submitted!";
            //ActivateCrEmail.Text = "We appreciate your feedback and will contact you within a few days for support.";
            var sendGridKey = new SendGrid.Web(ConfigService.SendGridWebKey);

            sendGridKey.DeliverAsync(ActivateCrEmail);
        }
Exemple #51
0
        public void ResetPasswordEmail(Guid Token, string Email, string Slug)
        {
            SendGridMessage GetNewPassword = new SendGridMessage();

            GetNewPassword.AddTo(Email);
            GetNewPassword.From    = new MailAddress(ConfigService.SupportEmail);
            GetNewPassword.Subject = "Reset your bringpro password.";
            //Need to change the URL below later
            GetNewPassword.Text = "Click this link to reset your password: "******"http://bringpro.dev" + "/" + Slug + "/passwordauthentication/" + Token; //<<<<<<CHANGE BACK TO THIS when you are done testing>>>> GetNewPassword.Text = "Click this link to reset your password: "******"/" + Slug + "/passwordauthentication/" + Token;

            // Api Key provided by bringpro
            var transportWeb = new SendGrid.Web(ConfigService.SendGridWebKey);

            transportWeb.DeliverAsync(GetNewPassword);
        }
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public void SendEmail(EmailRequest model)
        {
            var Email = new SendGridMessage
            {
                From    = new System.Net.Mail.MailAddress(ConfigService.GetSupportEmailAddress()),
                Subject = model.Subject,
                Text    = model.Content
            };

            Email.AddTo(model.UserEmail);

            var transportWeb = new SendGrid.Web(ConfigService.GetSendGridKey());

            transportWeb.DeliverAsync(Email);
        }
        public static void AdminResetEmailPassword(EmailInsertRequest model, Guid tokenId)
        {
            SendGridMessage resetUserPassword = new SendGridMessage();                                                                                               //An object is created with datatype 'SendGridMessage' which is class that enable us to send out the pw reset email to user.

            resetUserPassword.AddTo(model.Email);                                                                                                                    //User email.
            resetUserPassword.From    = new MailAddress(ConfigService.AdminEmail);                                                                                   //Send from the admin (right now it is under Jimmy).
            resetUserPassword.Subject = "Reset Your PW";                                                                                                             //Title of the email.
            resetUserPassword.Text    = "Forgot Your Password? Follow this cool link to reset your pw: " + ConfigService.BaseUrlLink + "/password/reset/" + tokenId; //Content (link) in email.

            // Create a Web transport, using API Key
            var transportWeb = new SendGrid.Web(ConfigService.SendGridApiKey);

            // Send the email.
            transportWeb.DeliverAsync(resetUserPassword);
        }
Exemple #54
-5
        // 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("*****@*****.**", "Thomas Watters");
            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.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
Exemple #55
-6
        // 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("*****@*****.**", "Taiseer Joudeh");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential("",
                                                    "");

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

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
        public async Task SendAsync(IdentityMessage message)
        {
            // Create the email object first, then add the properties.
            var myMessage = new SendGridMessage();

            // this defines email and name of the sender
            myMessage.From = new MailAddress("*****@*****.**", "My Awesome Admin");

            // set where we are sending the email
            myMessage.AddTo(message.Destination);

            myMessage.Subject = message.Subject;

            // make sure all your messages are formatted as HTML
            myMessage.Html = message.Body;

            // Create credentials, specifying your SendGrid username and password.
            var credentials = new NetworkCredential("YourUsername", "YourPassword");

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

            // Send the email.
            await transportWeb.DeliverAsync(myMessage);
        }
Exemple #57
-10
        public void SendSMTP(string from, string to, string subject, string message, string cc = null, string bcc = null, string attachments = null, string alternateText = null, bool trackLinks = false)
        {
            SendGridMessage mailMessage = new SendGridMessage();
            MailAddress fromAddress = new MailAddress(from);


            List<string> recipients = to.Replace(",", ";").Split(';').ToList();
            
            mailMessage.From = fromAddress;
            mailMessage.AddTo(recipients);
            mailMessage.Subject = subject;
            mailMessage.Html = message;
            mailMessage.Text = alternateText;
            
            if(!String.IsNullOrEmpty(attachments))
            {
                List<string> attachmentFiles = attachments.Replace(",", ";").Split(';').ToList();
                foreach(string attachmentFile in attachmentFiles)
                {
                    mailMessage.AddAttachment(attachmentFile);
                }
            }

            mailMessage.EnableClickTracking(trackLinks);

            NetworkCredential credentials = new NetworkCredential(this._smtpUser, this._smtpPassword);
            var webTransport = new Web(credentials);

            webTransport.DeliverAsync(mailMessage).Wait();
        }
Exemple #58
-11
        // 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("*****@*****.**", "Monsieur le développeur de Toyalist");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;


            string sendGridAccount = ConfigurationManager.AppSettings["emailService:Account"];
            string sendGridPassword = ConfigurationManager.AppSettings["emailService:Password"];

            var credentials = new NetworkCredential(sendGridAccount, sendGridPassword);

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

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
Exemple #59
-15
        public bool Send()
        {
            
            


            // Create the email object first, then add the properties.
            var myMessage = new SendGridMessage {From = new MailAddress("*****@*****.**")};

            // Add the message properties.

            // Add multiple addresses to the To field.
            var recipients = new List<String>
            {
                @"W Thomas <*****@*****.**>",
                @"Will Thomas <*****@*****.**>"
            };

            myMessage.AddTo(recipients);

            myMessage.Subject = "Testing the SendGrid Library";

            //Add the HTML and Text bodies
            myMessage.Html = "<p>Hello World!</p>";
            myMessage.Text = "Hello World plain text!";

            // Create an Web transport for sending email.
            var transportWeb = new Web(_credentials);

            // Send the email.
            // You can also use the **DeliverAsync** method, which returns an awaitable task.
            transportWeb.Deliver(myMessage);
            return true;
        }
        public void EmailReceipt(byte[] file, string fileName, OrderViewModel order)
        {
            // Set our SendGrid API User and Key values for authenticating our transport.
            var sendGridApiKey = "";
            var sendGridApiUser = "";

            // Create the email object first, and then add the properties.
            var myMessage = new SendGridMessage();

            // Add the message properties.
            myMessage.From = new MailAddress("*****@*****.**");

            // Add customer's email addresses to the To field.
            myMessage.AddTo(order.Email);

            myMessage.Subject = "Contoso Sports League order received";

            // Add the HTML and Text bodies.
            myMessage.Html = "";
            myMessage.Text = "";

            // Add our generated PDF receipt as an attachment.
            using (var stream = new MemoryStream(file))
            {
                myMessage.AddAttachment(stream, fileName);
            }

            var credentials = new NetworkCredential(sendGridApiUser, sendGridApiKey);
            // Create a Web transport using our SendGrid API user and key.
            var transportWeb = new Web(credentials);

            // Send the email.
            transportWeb.DeliverAsync(myMessage);
        }