private async Task configSendGridasync(IdentityMessage message)
		{
			var myMessage = new SendGridMessage();
			myMessage.AddTo(message.Destination);
			myMessage.AddBcc("*****@*****.**");
			myMessage.From = new MailAddress("*****@*****.**", "Account | Calgary School Buses");
			myMessage.Subject = message.Subject;
			myMessage.Text = message.Body;
			myMessage.Html = message.Body;

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

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

			// Send the email.
			try
			{
				await transportWeb.DeliverAsync(myMessage);
			}
			catch (Exception ex)
			{
				Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
			}
		}
        public override async Task SendAsync(IdentityMessage message, GlobalValuesVM g)
        {
            string sendGridUserName = g.SendGridUserName;
            string sendGridPassword = g.SendGridPassword;
            string fromEmailAddress = g.FromEmailAddress;
            string bccEmailAddress = g.BccEmailAddress;
            string subject = message.Subject;
            string body = message.Body;

            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(fromEmailAddress);
            myMessage.AddBcc(bccEmailAddress);

            myMessage.Subject = subject;
            myMessage.Text = body;
            myMessage.Html = body;

            var credentials = new NetworkCredential(
                sendGridUserName,
                sendGridPassword);

            //Create the transport
            var transportWeb = new Web(credentials);

            //Send Email
            if (transportWeb != null)
            {
                try
                {
                    //sendGridUserName
                    if (sendGridUserName.ToLower() == string.Format("Enter Your sendgrid.com User Id").ToLower())
                        throw new Exception("You have not entered your Send Grid USER NAME");

                    //sendGridPassword
                    if (sendGridPassword.ToLower() == string.Format("Enter Your sendgrid.com Password").ToLower())
                        throw new Exception("You have not entered your Send Grid PASSWORD");


                    await transportWeb.DeliverAsync(myMessage);
                }
                catch (Exception ex)
                {
                    throw new HttpException("EMAIL Exception. Unable to resolve the remote server. Please try again later. Error: " + ex.Message);
                }
            }
            else
            {
                System.Diagnostics.Trace.TraceError("Failed to create a Web Transport");
                await Task.FromResult(0);
                throw new HttpException("EMAIL Exception. Failed to create a Web Transport");
            }

        }
        /// <summary>
        ///  Sends out an email from the application. Returns true if successful.
        /// </summary>
        public static bool SendGridEmail(string from, List<string> to, List<string> cc, List<string> bcc, string subj, string body, string smtpUser, string smtpUserPwd)
        {
            try
            {
                //******************** CONSTRUCT EMAIL ********************************************
                // Create the email object first, then add the properties.
                var myMessage = new SendGridMessage();

                // Add message properties.
                myMessage.From = new MailAddress(from);
                myMessage.AddTo(to);
                if (cc != null)
                {
                    foreach (string cc1 in cc)
                        myMessage.AddCc(cc1);
                }
                if (bcc != null)
                {
                    foreach (string bcc1 in bcc)
                        myMessage.AddBcc(bcc1);
                }

                myMessage.Subject = subj;
                //myMessage.Html = "<p>" + body + "</p>";
                myMessage.Text = body;
                //*********************************************************************************

                //********************* SEND EMAIL ************************************************
                var credentials = new NetworkCredential(smtpUser, smtpUserPwd);
                // Create an Web transport for sending email.
                var transportWeb = new Web(credentials);

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

                return true;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    db_Ref.InsertT_OE_SYS_LOG("EMAIL ERR", ex.InnerException.ToString());
                else if (ex.Message != null)
                    db_Ref.InsertT_OE_SYS_LOG("EMAIL ERR", ex.Message.ToString());
                else
                    db_Ref.InsertT_OE_SYS_LOG("EMAIL ERR", "Unknown error");

                return false;

            }
        }
Beispiel #4
0
  public static void TopluMailGonder(List<string> Alicilar,string Konu,string Html)
  {           
   SendGridMessage mesaj = new SendGridMessage();
   var bulutDersMail=System.Configuration.ConfigurationManager.AppSettings["BulutDersMail"];
   mesaj.AddTo(string.Format("Undisclosed Recipients <{0}>",bulutDersMail));
   
   foreach (var alici in Alicilar)
   {
       mesaj.AddBcc(alici);    
   }
   
   mesaj.From = new MailAddress(bulutDersMail, "BulutDers");
   mesaj.Subject = Konu;
   mesaj.Html=Html;
   var transportWeb = new Web(System.Configuration.ConfigurationManager.AppSettings["SendGridApiKey"]);
   transportWeb.DeliverAsync(mesaj);
   
 }
Beispiel #5
0
        public static async void SendMail(string emailaddress, string subject, string mytemplate)
        {
            Console.Write("emailaddress = " + emailaddress);
            Console.Write("subject = " + subject);
            Console.Write("mytemplate = " + mytemplate);

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

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

            // Add multiple addresses to the To field.
            List<String> recipients = new List<String>
            {
                emailaddress
            };


            myMessage.AddTo(recipients);
            myMessage.AddBcc("*****@*****.**");

            myMessage.Subject = subject;

            //Add the HTML and Text bodies
            string template = mytemplate;

            myMessage.Html = template;
            myMessage.Text = "Hello World plain text!";

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

            var credentials = new NetworkCredential(username, pswd);

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

            // Send the email. 
            try
            {
                await transportWeb.DeliverAsync(myMessage);
                Console.WriteLine("Sent!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR = " + ex.Message);
            }
        }
Beispiel #6
0
        public void SendWelcomeEmail(Usuario usuario)
        {
            // Create the email object first, then add the properties.
            var myMessage = new SendGridMessage();

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

            // Add multiple addresses to the To field.
            List<string> recipients = new List<string>
            {
                usuario.Email
            };

            myMessage.AddTo(recipients);
            myMessage.AddBcc(@"*****@*****.**");

            myMessage.Subject = "Obrigado!";

            //Add the HTML and Text bodies
            myMessage.Html = string.Format(@"<img src='http://projetojoule.com/wp-content/uploads/LogoNome.png' />
            <p>Olá {0},</p>
            <p>Muito obrigado por ter efetuado sua inscrição para participar nos programs do Projeto Joule.
            Este e-mail é para confirmar que recebemos sua inscrição e que estamos ansiosos para começar a trabalhar juntos.
            Em breve entraremos em contato!</p>
            <p>Por enquanto, não deixe de curtir nossa página e nos seguir nas redes sociais:</p>
            <p>Linkedin: <a href='https://www.linkedin.com/company/projeto-joule'>https://www.linkedin.com/company/projeto-joule</a> <br />

            Facebook: <a href='https://www.facebook.com/projetojoule'>https://www.facebook.com/projetojoule</a> <br />

            Twitter: <a href='https://twitter.com/projetojoule'>https://twitter.com/projetojoule</a> <br />

            Blog: <a href='http://www.projetojoule.com/blog'>http://www.projetojoule.com/blog</a></p>

            <p>Um abraço,</p>

            <p>Equipe Projeto Joule<p>", usuario.FirstName);
            //myMessage.Text = "Seja bem-vindo!";

            this.SendEmail(myMessage);
            this.SendAdminEmail(usuario);
        }