示例#1
0
        public Task SendEmailAsync(EmailModel model)
        {
            // Plug in your email service here to send an email.
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(model.To);
            myMessage.From    = new System.Net.Mail.MailAddress(model.From, model.Subject);
            myMessage.Subject = model.Subject;
            myMessage.Text    = model.TextBody;
            myMessage.Html    = model.HtmlBody;

            var credentials = new System.Net.NetworkCredential(Startup.Configuration["Email:SendGrid:Username"], Startup.Configuration["Email:SendGrid:Password"]);
            // 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));
            }
        }
示例#2
0
        public void TestMethod1()
        {
            try
            {
                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo("*****@*****.**");
                myMessage.From    = new MailAddress("*****@*****.**", "First Last");
                myMessage.Subject = "Sending with SendGrid is Fun screen2";
                myMessage.Text    = "and easy to do anywhere, even with C#";

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

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

                //transportWeb.DeliverAsync(myMessage).Wait();
                transportWeb.DeliverAsync(myMessage).Wait();
            }
            catch (InvalidApiRequestException ex)
            {
                var detalle = new StringBuilder();

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

                throw new ApplicationException(detalle.ToString(), ex);
            }
        }
示例#3
0
        }                                                 // set only via Secret Manager

        public Task SendEmailAsync(string email, string subject, string message)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(email);
            myMessage.From    = new System.Net.Mail.MailAddress("*****@*****.**", "PuzzleAdv");
            myMessage.Subject = subject;
            myMessage.Text    = message;
            myMessage.Html    = message;
            var credentials = new System.Net.NetworkCredential(
                Options.SendGridUser,
                Options.SendGridKey);
            // 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));
            }
        }
示例#4
0
        public static void Mail(string useremail, string message)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(useremail);
            myMessage.From    = new MailAddress(ConfigurationManager.AppSettings["Email"]);
            myMessage.Subject = "Email";
            myMessage.Html    = message;

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

            //return View("ddd");

            if (transportWeb != null)
            {
                try
                {
                    transportWeb.DeliverAsync(myMessage);
                    // return View("Success");
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                // Trace.TraceError("Failed to create Web transport.");
                // await Task.FromResult(0);
            }
            //return null;
        }
 public void Send(Context context)
 {
     Task.Run(() =>
     {
         try
         {
             var sendGridMessage  = new SendGrid.SendGridMessage();
             sendGridMessage.From = Addresses.From(From);
             Addresses.GetEnumerable(
                 context: context,
                 addresses: To)
             .ForEach(to => sendGridMessage.AddTo(CreateAddressInfo(to)));
             Addresses.GetEnumerable(
                 context: context,
                 addresses: Cc)
             .ForEach(cc => sendGridMessage.AddCc(CreateMailAddress(cc)));
             Addresses.GetEnumerable(
                 context: context,
                 addresses: Bcc)
             .ForEach(bcc => sendGridMessage.AddBcc(CreateMailAddress(bcc)));
             sendGridMessage.Subject = Subject;
             sendGridMessage.Text    = Body;
             new SendGrid.Web(new System.Net.NetworkCredential(
                                  Parameters.Mail.SmtpUserName,
                                  Parameters.Mail.SmtpPassword))
             .DeliverAsync(sendGridMessage);
         }
         catch (Exception e)
         {
             new SysLogModel(Context, e);
         }
     });
 }
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
            var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
            IdentityResult result = manager.Create(user, Password.Text);
            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo(Email.Text);
                myMessage.From = new MailAddress("*****@*****.**", "ToDoTaskList");
                myMessage.Subject = "Welcome to ToDoTaskList!";
                myMessage.Text = "ToDoTaskList is an iterative tasklist that helps you seize the day.";

                var transportWeb = new SendGrid.Web("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");
                transportWeb.DeliverAsync(myMessage);
                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
示例#7
0
        private static SendGrid.SendGridMessage getSendGridMessage(EmailMessage message)
        {
            var m = new SendGrid.SendGridMessage();

            m.From    = message.From.ToMailAddress();
            m.ReplyTo = message.ReplyToAddresses.Select(i => i.ToMailAddress()).ToArray();

            m.To  = message.ToAddresses.Select(i => i.ToMailAddress()).ToArray();
            m.Cc  = message.CcAddresses.Select(i => i.ToMailAddress()).ToArray();
            m.Bcc = message.BccAddresses.Select(i => i.ToMailAddress()).ToArray();

            m.Subject = message.Subject;

            foreach (var i in message.CustomHeaders)
            {
                m.Headers.Add(i.Item1, i.Item2);
            }

            m.Text = htmlToPlainText(message.BodyHtml);
            m.Html = message.BodyHtml;

            foreach (var i in message.Attachments)
            {
                if (i.Stream == null)
                {
                    m.AddAttachment(i.FilePath);
                }
                else
                {
                    m.AddAttachment(i.Stream, i.AttachmentDisplayName);
                }
            }

            return(m);
        }
示例#8
0
        public async Task SendAsync(IdentityMessage message)
        {
            // Plug in your email service here to send an email.
            // Plug in your SMS service here to send a text message
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From    = new MailAddress(ConfigurationManager.AppSettings["Email"]);
            myMessage.Subject = message.Subject;
            myMessage.Html    = message.Body;

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

            //await transportWeb.DeliverAsync(myMessage);
            //return Task.FromResult(0);
            if (transportWeb != null)
            {
                try
                {
                    await transportWeb.DeliverAsync(myMessage);
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
示例#9
0
        public Task SendEmailAsync(EmailModel model)
        {
            // Plug in your email service here to send an email.
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(model.To);
            myMessage.From    = new System.Net.Mail.MailAddress(model.From, model.DisplayName);
            myMessage.Subject = model.Subject;
            myMessage.Text    = model.TextBody;
            myMessage.Html    = model.HtmlBody;
            //myMessage.AddAttachment(new FileStream(Path.Combine(_env.WebRootPath, "templates\\qlogo.png"), FileMode.Open, FileAccess.Read), "qlogo");

            var credentials = new System.Net.NetworkCredential(Startup.Configuration["SendGrid:Username"], Startup.Configuration["SendGrid:Password"]);
            // 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));
            }
        }
示例#10
0
        }                                                 // set only via Secret Manager

        public Task SendEmailAsync(string email, string subject, string message)
        {
            // Plug in your email service here to send an email.
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(email);
            myMessage.From    = new System.Net.Mail.MailAddress("*****@*****.**", "Kevin Grieger");
            myMessage.Subject = subject;
            myMessage.Text    = message;
            myMessage.Html    = message;

            var credentials = new System.Net.NetworkCredential(
                Options.SendGridUser,
                Options.SendGridKey);
            // 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));
            }
        }
        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"));
        }
示例#12
0
        public Task SendEmailAsync(string destEmail, MailAddress sourceEmail, string subject, string message)
        {
            try
            {
                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo(destEmail);
                myMessage.From    = sourceEmail;
                myMessage.Subject = subject;
                myMessage.Text    = message;
                myMessage.Html    = message;
                myMessage.AddBcc(_config["mailSettings:contactForm:destinationEmailAddress"]);
                var credentials = new NetworkCredential(
                    _options.SendGridUser,
                    _options.SendGridPassword);

                var transportWeb = new SendGrid.Web(credentials);

                return(transportWeb.DeliverAsync(myMessage));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in Message Sender: SendEmailAsync", ex);
                throw ex;
            }
        }
        public PartialViewResult Indicar(IndicacaoModel model)
        {
            ViewBag.Estabelecimentos = Context.Estabelecimentos
                                       .ToList()
                                       .OrderBy(e => e.Nome)
                                       .Select(e => new SelectListItem()
            {
                Text  = e.Nome,
                Value = e.Id.ToString()
            });

            if (ModelState.IsValid)
            {
                try
                {
                    var pessoa  = GetUsuario();
                    var usuario = Context.Pessoas.FirstOrDefault(e => e.Usuario == model.Email);
                    if (pessoa.Usuario == model.Email || usuario != null)
                    {
                        ModelState.AddModelError("Email", "Não foi possível indicar esse e-mail");
                        return(PartialView(model));
                    }
                    var indicacao = new Indicacao()
                    {
                        EmailDestino      = model.Email,
                        PessoaId          = pessoa.Id,
                        EstabelecimentoId = model.EstabelecimentoSelecionado.Value
                    };

                    Context.Indicacoes.Add(indicacao);
                    Context.SaveChanges();

                    var estabelecimento = Context.Estabelecimentos.Find(model.EstabelecimentoSelecionado.Value);

                    var usuarioEmail = ConfigurationManager.AppSettings["SendgridAccount"];
                    var senhaEmail   = ConfigurationManager.AppSettings["SendgridKey"];

                    var email = new SendGrid.SendGridMessage(
                        new MailAddress("*****@*****.**"),
                        new MailAddress[] { new MailAddress(model.Email) },
                        "Indicação de posto",
                        "<p>Você foi indicado para abastecer no posto " + estabelecimento.Nome + ", clique <a href=\"" + Url.Action("Cadastro", "Conta", new { email = model.Email }, Request.Url.Scheme) + "\">aqui</a> para se cadastrar</p>",
                        "Você foi indicado para abastecer no posto " + estabelecimento.Nome);
                    var client = new SendGrid.Web(new System.Net.NetworkCredential(usuarioEmail, senhaEmail));
                    client.Deliver(email);
                }
                catch (DbUpdateException)
                {
                    ModelState.AddModelError("Email", "Não foi possível indicar esse e-mail");
                    return(PartialView(model));
                }
                catch (Exception)
                {
                }
            }

            return(PartialView());
        }
        public static async Task SendEmail(string to, string subject, string body)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(to);
            myMessage.From    = new System.Net.Mail.MailAddress("*****@*****.**", "Assessment Application");
            myMessage.Subject = subject;
            myMessage.Text    = body;

            var transportWeb = new SendGrid.Web(AppSettings.SendGridApiKey);
            await transportWeb.DeliverAsync(myMessage);
        }
示例#15
0
        public async Task ResetPasswordAsync(BlogUser user, string callbackUrl)
        {
            var emailMessage = new SendGrid.SendGridMessage();

            emailMessage.From    = new MailAddress(config["Site:Email"], config["Site:Username"]);
            emailMessage.Subject = "Password reset.";
            emailMessage.Text    = $"Please use the following link to <a href='{callbackUrl}'>reset your password</a>.";
            emailMessage.AddTo($"{user.Email}");

            var transportWeb = new SendGrid.Web(config["SendGrid:ApiKey"]);
            await transportWeb.DeliverAsync(emailMessage);
        }
示例#16
0
        public async Task ConfirmEmailAsync(BlogUser user, string callbackUrl)
        {
            var emailMessage = new SendGrid.SendGridMessage();

            emailMessage.From    = new MailAddress(config["Site:Email"], config["Site:Username"]);
            emailMessage.Subject = "Thanks for registration!";
            emailMessage.Text    = $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>";
            emailMessage.AddTo($"{user.Email}");

            var transportWeb = new SendGrid.Web(config["SendGrid:ApiKey"]);
            await transportWeb.DeliverAsync(emailMessage);
        }
示例#17
0
        public async Task SendEmailAsync(ContactViewModel viewModel)
        {
            var emailMessage = new SendGrid.SendGridMessage();

            emailMessage.From    = new MailAddress($"{viewModel.Email}", $"{viewModel.Name}");
            emailMessage.Subject = viewModel.Subject;
            emailMessage.Text    = viewModel.Message;
            emailMessage.AddTo(config["Site:Email"]);

            var transportWeb = new SendGrid.Web(config["SendGrid:ApiKey"]);
            await transportWeb.DeliverAsync(emailMessage);
        }
示例#18
0
        /// <summary>
        /// Send an error report email to me, for debugging issues for the project.
        /// </summary>
        /// <param name="ex">Exception caught by the try-catch block.</param>
        private void SendErrorMessage(Exception ex)
        {
            var message = new SendGrid.SendGridMessage();

            message.AddTo("*****@*****.**");
            message.From    = new MailAddress("*****@*****.**", "Service Bus Error");
            message.Subject = "Service Bus Error";
            message.Text    = ex.Message;

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

            transport.DeliverAsync(message).Wait();
        }
示例#19
0
 public Task SendEmailAsync(string email, string subject, string message)
 {
     // Plug in your email service here to send an email.
     var myMessage = new SendGrid.SendGridMessage();
     myMessage.AddTo(email);
     myMessage.From = new System.Net.Mail.MailAddress("*****@*****.**", "Doron Grinzaig");
     myMessage.Subject = subject;
     myMessage.Text = message;
     myMessage.Html = message;
     var credentials = new System.Net.NetworkCredential(Options.SendGridUser, Options.SendGridKey);
     // Create a Web transport for sending email.
     var transportWeb = new SendGrid.Web(credentials);
     // Send the email.
     return transportWeb.DeliverAsync(myMessage);
 }
示例#20
0
        public static async Task <bool> SendEmail(string Subject, string PlainText, string HTMLText, string To)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(To);
            myMessage.From    = new MailAddress("*****@*****.**", "ChariFit");
            myMessage.Subject = Subject;
            myMessage.Text    = PlainText;
            myMessage.Html    = HTMLText;

            var transportWeb = new SendGrid.Web(ConfigurationManager.AppSettings["SendGridAPIKey"]);
            await transportWeb.DeliverAsync(myMessage);

            return(true);
        }
示例#21
0
        public static async Task<bool> SendEmail(string Subject, string PlainText,string HTMLText, string To)
        {
            
            var myMessage = new SendGrid.SendGridMessage();
            myMessage.AddTo(To);
            myMessage.From = new MailAddress("*****@*****.**", "ChariFit");
            myMessage.Subject = Subject;
            myMessage.Text = PlainText ;
            myMessage.Html = HTMLText;

            var transportWeb = new SendGrid.Web(ConfigurationManager.AppSettings["SendGridAPIKey"]);
            await transportWeb.DeliverAsync(myMessage);
            
            return true;
        }
示例#22
0
        private static void SendEmail(string to, string from, string fromName)
        {
            // Create the email object first, then add the properties.
            var myMessage = new SendGrid.SendGridMessage();
            myMessage.AddTo(to);
            myMessage.From = new MailAddress(from, fromName);
            myMessage.Subject = "Testing the SendGrid Library";
            myMessage.Text = "Hello World! %tag%";

            var subs = new List<String> { "私は%type%ラーメンが大好き" };
            myMessage.AddSubstitution("%tag%", subs);
            myMessage.AddSection("%type%", "とんこつ");

            SendAsync(myMessage);
        }
        public async Task <IHttpActionResult> Send(Guid id)
        {
            var userBooking = await db.Bookings.FirstOrDefaultAsync(booking => booking.Id == id);


            if (userBooking == null)
            {
                return(NotFound());
            }

            var user =
                await db.Users.FirstOrDefaultAsync(applicationUser => applicationUser.Id == userBooking.CustomerId);

            if (user == null)
            {
                return(NotFound());
            }

            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(user.Email);
            myMessage.From    = new MailAddress("*****@*****.**", "BookingBlock Reminders");
            myMessage.Subject = "You have an upcoming appointment";
            myMessage.Text    = "You have a booking @ " + userBooking.Date;

            if (!string.IsNullOrWhiteSpace(user.PhoneNumber))
            {
                try
                {
                    await Sms(user.PhoneNumber, myMessage.Text);
                }
                catch (Exception)
                {
                    // throw;
                }
            }

            var transportWeb =
                new SendGrid.Web(new NetworkCredential()
            {
                UserName = ConfigurationManager.AppSettings["SendGridUsername"],
                Password = ConfigurationManager.AppSettings["SendGridPassword"]
            });
            await transportWeb.DeliverAsync(myMessage);

            return(Ok());
        }
示例#24
0
        public static void SendMail(string subject, string body) {
            var email = new SendGrid.SendGridMessage {
                From = new MailAddress("*****@*****.**")
            };

            email.AddTo(ConfigurationManager.AppSettings["ERROR_EMAIL"]);
            email.Subject = subject;

            email.Html = body.Replace(System.Environment.NewLine, "<br/>");
    
            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["SENDGRID_USERNAME"], ConfigurationManager.AppSettings["SENDGRID_PASSWORD"]);
            var transportWeb = new SendGrid.Web(credentials);

            var task = transportWeb.DeliverAsync(email);

            Task.WaitAll(task);
        }
        public Task SendEmailAsync(string email, string subject, string message)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(email);
            myMessage.From    = new System.Net.Mail.MailAddress("*****@*****.**", "Identity Introduction");
            myMessage.Subject = subject;
            myMessage.Text    = message;
            myMessage.Html    = message;
            var credentials = new System.Net.NetworkCredential(
                Options.SendGridUser,
                Options.SendGridKey);
            // Create web transport for sending email
            var transportWeb = new SendGrid.Web(credentials);

            return(transportWeb.DeliverAsync(myMessage));
        }
        public static void ConPaidMail(string ConEmail, string ConUsername, decimal Amount)
        {
            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");

            myMessage.AddTo(ConEmail);
            myMessage.From    = new MailAddress("*****@*****.**", "Admin");
            myMessage.Subject = "Job Complete!!";
            String message = "Hello " + ConUsername + "," + "<br>" + "<br>" + "Thank you for using Work Warriors! $" + Amount + " has been paid to your account!";

            myMessage.Html = message;
            var credentials  = new NetworkCredential(name, pass);
            var transportWeb = new SendGrid.Web(credentials);

            transportWeb.DeliverAsync(myMessage);
        }
        public async Task SendAsync(IdentityMessage message)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.Text    = message.Body;
            myMessage.Subject = message.Subject;

            var transportWeb =
                new SendGrid.Web(new NetworkCredential()
            {
                UserName = ConfigurationManager.AppSettings["SendGridUsername"],
                Password = ConfigurationManager.AppSettings["SendGridPassword"]
            });

            await transportWeb.DeliverAsync(myMessage);
        }
示例#28
0
        public static bool sendEmail(string subject, string body, string email)
        {
            try {
                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo(email);
                myMessage.From    = new MailAddress(Constant.EMAIL_FROM_ADDRESS, Constant.EMAIL_FROM_NAME);
                myMessage.Subject = subject;
                myMessage.Text    = body;

                var transportWeb = new SendGrid.Web(Constant.SENDGRID_API_TOKEN);
                transportWeb.DeliverAsync(myMessage).Wait();
            } catch {
                return(false);
            }

            return(true);
        }
示例#29
0
 public void Send()
 {
     Task.Run(() =>
     {
         var sendGridMessage  = new SendGrid.SendGridMessage();
         sendGridMessage.From = Addresses.From(From);
         Addresses.GetEnumerable(To).ForEach(to => sendGridMessage.AddTo(to));
         Addresses.GetEnumerable(Cc).ForEach(cc => sendGridMessage.AddCc(cc));
         Addresses.GetEnumerable(Bcc).ForEach(bcc => sendGridMessage.AddBcc(bcc));
         sendGridMessage.Subject = Subject;
         sendGridMessage.Text    = Body;
         new SendGrid.Web(new System.Net.NetworkCredential(
                              Parameters.Mail.SmtpUserName,
                              Parameters.Mail.SmtpPassword))
         .DeliverAsync(sendGridMessage);
     });
 }
示例#30
0
        public static bool sendEmail(string subject, string body, string email)
        {
            try {
                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo(email);
                myMessage.From    = new MailAddress("*****@*****.**", "CashFlow");
                myMessage.Subject = subject;
                myMessage.Text    = body;

                var transportWeb = new SendGrid.Web(Constant.SENDGRID_API_TOKEN);
                transportWeb.DeliverAsync(myMessage).Wait();
            } catch {
                return(false);
            }

            return(true);
        }
        }                                                //set only via Secret Manager

        // https://azure.microsoft.com/en-us/documentation/articles/sendgrid-dotnet-how-to-send-email/#create-a-sendgrid-account
        public Task SendEmailAsync(string email, string subject, string message)
        {
            // Plug in your email service here to send an email.
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(email);
            myMessage.From    = new System.Net.Mail.MailAddress(Options.SenderEmail, Options.SenderName);
            myMessage.Subject = subject;
            myMessage.Text    = message;
            myMessage.Html    = message;
            var credentials = new System.Net.NetworkCredential(
                Options.SendGridUser,
                Options.SendGridKey);
            // Create a Web transport for sending email.
            var transportWeb = new SendGrid.Web(credentials);

            return(transportWeb.DeliverAsync(myMessage));
        }
示例#32
0
        public Task ContactUsEmailAsync(string emailFrom, string emailTo, string message
                                        , string senderName, string subject)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(emailTo);
            myMessage.From    = new System.Net.Mail.MailAddress(emailFrom, senderName);
            myMessage.Subject = subject;
            myMessage.Text    = message;
            myMessage.Html    = message;
            var credentials = new System.Net.NetworkCredential(
                Options.SendGridUser,
                Options.SendGridKey);
            // Create a Web transport for sending email.
            var transportWeb = new SendGrid.Web(credentials);

            return(transportWeb.DeliverAsync(myMessage));
        }
示例#33
0
        private static void SendEmail(string to, string from, string fromName)
        {
            // Create the email object first, then add the properties.
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(to);
            myMessage.From    = new MailAddress(from, fromName);
            myMessage.Subject = "Testing the SendGrid Library";
            myMessage.Text    = "Hello World! %tag%";

            var subs = new List <String> {
                "私は%type%ラーメンが大好き"
            };

            myMessage.AddSubstitution("%tag%", subs);
            myMessage.AddSection("%type%", "とんこつ");

            SendAsync(myMessage);
        }
示例#34
0
        public async Task SendEmail(string emailAddress, string subject, string body)
        {
            SendGrid.SendGridMessage message = new SendGrid.SendGridMessage();
            message.From = new System.Net.Mail.MailAddress("*****@*****.**");
            message.To   = new System.Net.Mail.MailAddress[]
            {
                new System.Net.Mail.MailAddress(emailAddress)
            };
            message.Subject = subject;
            message.Html    = body;
            message.DisableClickTracking();
            message.DisableOpenTracking();

            string userName    = System.Web.Configuration.WebConfigurationManager.AppSettings["SendGridUserName"];
            string password    = System.Web.Configuration.WebConfigurationManager.AppSettings["SendGridPassword"];
            var    credentials = new NetworkCredential(userName, password);

            await new SendGrid.Web(credentials).DeliverAsync(message);
        }
        public async Task <IHttpActionResult> SendEmail(string address)
        {
            var myMessage = new SendGrid.SendGridMessage();

            myMessage.AddTo(address);
            myMessage.From    = new MailAddress("*****@*****.**", "BookingBlock Reminders");
            myMessage.Subject = "You have an upcoming appointment";
            myMessage.Text    = "You have a booking @ " + DateTime.Now;

            var transportWeb =
                new SendGrid.Web(new NetworkCredential()
            {
                UserName = ConfigurationManager.AppSettings["SendGridUsername"],
                Password = ConfigurationManager.AppSettings["SendGridPassword"]
            });
            await transportWeb.DeliverAsync(myMessage);

            return(Ok());
        }
示例#36
0
        public AuthMessageSenderOptions Options { get; }  // set only via Secret Manager

        public Task SendEmailAsync(string email, string subject, string message)
        {
            var myMessage = new SendGrid.SendGridMessage();
            myMessage.AddTo(email);
            myMessage.From = new System.Net.Mail.MailAddress("*****@*****.**", "PuzzleAdv");
            myMessage.Subject = subject;
            myMessage.Text = message;
            myMessage.Html = message;
            var credentials = new System.Net.NetworkCredential(
                Options.SendGridUser,
                Options.SendGridKey);
            // 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);
            }
        }
示例#37
0
        public static bool Send(string recipient, string subject, string message, string senderEmail="*****@*****.**", string sender="Tuffab")
        {

            try
            {
                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo(recipient);
                myMessage.From = new MailAddress(sender,senderEmail);
                myMessage.Subject = subject;
                myMessage.Text = message;

                var transportWeb = new SendGrid.Web("");
                transportWeb.DeliverAsync(myMessage).Wait();

            }
            catch(Exception ex)
            {
                throw ex; 
                return false; 
            }
            return true; 

        }
        public ActionResult AddPerson(StudentToAdd student)
        {
            try
            {
                StudentManipulation.Insert(student);

                //Email Information
                var myMessage = new SendGrid.SendGridMessage();
                myMessage.AddTo("*****@*****.**");
                myMessage.From = new MailAddress("*****@*****.**", "USA Music Department");
                myMessage.Subject = "New Student";
                myMessage.Text = student.StudentFirstName + " " + student.StudentLastName + " has submitted an application as of " + DateTime.Now + ".";
                var transportWeb = new SendGrid.Web("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");
                transportWeb.DeliverAsync(myMessage);
                //Email Information

                return Redirect("http://www.southalabama.edu/colleges/music/");

            }
            catch
            {
                return View();
            }
        }
        public AuthMessageSenderOptions Options { get; }  // set only via Secret Manager

        public Task SendEmailAsync(string email, string subject, string message)
        {
            // Plug in your email service here to send an email.
            var myMessage = new SendGrid.SendGridMessage();
            myMessage.AddTo(email);
            myMessage.From = new System.Net.Mail.MailAddress("*****@*****.**", "Joe Smith");
            myMessage.Subject = subject;
            myMessage.Text = message;
            myMessage.Html = message;
            var credentials = new System.Net.NetworkCredential(
                Options.SendGridUser,
                Options.SendGridKey);
            // 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);
            }
        }
示例#40
0
 public Task SendEmailAsync(string email, string subject, string message)
 {
     // Plug in your email service here to send an email.
     var myMessage = new SendGrid.SendGridMessage();
     myMessage.AddTo(email);
     myMessage.From = new System.Net.Mail.MailAddress("*****@*****.**", "Chirp Team");
     myMessage.Subject = subject;
     myMessage.Text = message;
     myMessage.Html = message;
     var credentials = new System.Net.NetworkCredential(
         Options.SendGridUser,
         Options.SendGridPassword);
     // 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);
     }
 }
        private static SendGrid.SendGridMessage getSendGridMessage( EmailMessage message )
        {
            var m = new SendGrid.SendGridMessage();

            m.From = message.From.ToMailAddress();
            m.ReplyTo = message.ReplyToAddresses.Select( i => i.ToMailAddress() ).ToArray();

            m.To = message.ToAddresses.Select( i => i.ToMailAddress() ).ToArray();
            m.Cc = message.CcAddresses.Select( i => i.ToMailAddress() ).ToArray();
            m.Bcc = message.BccAddresses.Select( i => i.ToMailAddress() ).ToArray();

            m.Subject = message.Subject;

            foreach( var i in message.CustomHeaders )
                m.Headers.Add( i.Item1, i.Item2 );

            m.Text = htmlToPlainText( message.BodyHtml );
            m.Html = message.BodyHtml;

            foreach( var i in message.Attachments ) {
                if( i.Stream == null )
                    m.AddAttachment( i.FilePath );
                else
                    m.AddAttachment( i.Stream, i.AttachmentDisplayName );
            }

            return m;
        }
示例#42
0
		/// <summary>
		/// Send an error report email to me, for debugging issues for the project.
		/// </summary>
		/// <param name="ex">Exception caught by the try-catch block.</param>
		private void SendErrorMessage(Exception ex)
		{
			var message = new SendGrid.SendGridMessage();
			message.AddTo("*****@*****.**");
			message.From = new MailAddress("*****@*****.**", "Service Bus Error");
			message.Subject = "Service Bus Error";
			message.Text = ex.Message;

			var transport = new SendGrid.Web("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");
			transport.DeliverAsync(message).Wait();
		}