示例#1
0
        public static string SendMailBySendGrid(string Html, string Subject, string UserId, string Password, string FromName, string FromEmail, string ToEmail)
        {
            string sendMailBySendGrid = string.Empty;

            try
            {
                //var smtp = new SmtpClient();
                //smtp.Port = 25;
                //smtp.Host = "smtp.sendgrid.net";
                SendGrid myMessage = SendGridMail.SendGrid.GetInstance();
                myMessage.AddTo(ToEmail);
                myMessage.From    = new MailAddress(FromEmail);
                myMessage.Subject = Subject;

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

                //myMessage.InitializeFilters();
                var credentials = new NetworkCredential(UserId, Password);

                var transportWeb = SMTP.GetInstance(credentials);

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

                sendMailBySendGrid = "success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                sendMailBySendGrid = "failed";
            }
            return(sendMailBySendGrid);
        }
        public void TestAddTo()
        {
            var foo = new Mock <IHeader>();

            var sg = new SendGrid(foo.Object);

            sg.AddTo("*****@*****.**");
            Assert.AreEqual("*****@*****.**", sg.To.First().ToString(), "Single To Address");

            sg = new SendGrid(foo.Object);
            var strings = new String[2];

            strings[0] = "*****@*****.**";
            strings[1] = "*****@*****.**";
            sg.AddTo(strings);
            Assert.AreEqual("*****@*****.**", sg.To[0].ToString(), "Multiple To addresses, check first one");
            Assert.AreEqual("*****@*****.**", sg.To[1].ToString(), "Multiple To addresses, check second one");

            sg = new SendGrid(foo.Object);
            var a = new Dictionary <String, String>();

            a.Add("DisplayName", "Eric");
            var datastruct = new Dictionary <string, IDictionary <string, string> > {
                { "*****@*****.**", a }
            };

            sg.AddTo(datastruct);
            Assert.AreEqual("Eric", sg.To.First().DisplayName, "Single address with args");
        }
        public override DeferredProcessExitCode Execute(MessageBroker messageBroker)
        {
            try
            {
                //AddresseeClient ac = new AddresseeClient();
                //Addressee a = ac.GetByPartitionAndRowKey(AddresseeClient.GetPartitionKeyForEmail(To), To);
                //if (a.Unsubscribed)
                //{
                //    return DeferredProcessExitCode.NothingToDo;
                //}

                SendGrid myMessage = SendGrid.GetInstance();

                myMessage.From    = new MailAddress(FromEmail, FromDisplay);
                myMessage.Subject = Subject;

                myMessage.AddTo(To);
                myMessage.Html = Body;

                SendByWeb(myMessage);

                return(DeferredProcessExitCode.Success);
            }
            catch
            {
                return(DeferredProcessExitCode.Error);
            }
        }
        public string SendMail(string from, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName = "", string sendgridPassword = "")
        {
            string sendMailBySendGrid = string.Empty;

            try
            {
                //var smtp = new SmtpClient();
                //smtp.Port = 25;
                //smtp.Host = "smtp.sendgrid.net";
                SendGrid myMessage = SendGridMail.SendGrid.GetInstance();
                myMessage.AddTo(to);
                myMessage.From    = new MailAddress(from);
                myMessage.Subject = subject;

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

                //myMessage.InitializeFilters();
                var credentials = new NetworkCredential(sendgridUserName, sendgridPassword);

                var transportWeb = SMTP.GetInstance(credentials);

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

                sendMailBySendGrid = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(sendMailBySendGrid);
        }
示例#5
0
        public void SendMail(string fromemail, string fromdisplay, string to, string subject, string body)
        {
            try
            {
                trycount++;
                SendGrid myMessage = SendGrid.GetInstance();

                myMessage.From    = new MailAddress(fromemail, fromdisplay);
                myMessage.Subject = subject;

                myMessage.AddTo(to);
                myMessage.Html = body;

                SendByWeb(myMessage);
                done = true;
            }
            catch (Exception e)
            {
                var excp = e;
                var str  = "";
            }
            if (!done && trycount <= 3)
            {
                SendMail(fromemail, fromdisplay, to, subject, body);
            }
        }
示例#6
0
        public static void NotifyAdminAboutNewUnrecognizedVin(string vin)
        {
            SendGrid message = SendGrid.GetInstance();

            foreach (string email in AdministratorPrivateEmails)
            {
                message.AddTo(email);
            }
            message.From    = new MailAddress(SystemFromEmail);
            message.Subject = "VTS Automonitoring - new Unrecognized Vin";
            message.Html    = String.Format("<p>Unrecognized VIN has been supplied by someone: {0}</p>", vin);
            SMTP transport = SMTP.GetInstance(SendGridCredentials);

            transport.Deliver(message);
        }
示例#7
0
        public static void NotifyAdminAboutVehicleRegistration(string vin, string modelName)
        {
            SendGrid message = SendGrid.GetInstance();

            foreach (string email in AdministratorPrivateEmails)
            {
                message.AddTo(email);
            }
            message.From    = new MailAddress(SystemFromEmail);
            message.Subject = "VTS Automonitoring - new Vehicle has registered";
            message.Html    = String.Format("<p>Model: {1}</p> \r\n Vin: {0}", vin, modelName);
            SMTP transport = SMTP.GetInstance(SendGridCredentials);

            transport.Deliver(message);
        }
示例#8
0
        public static void NotifyAdminAboutUserRegistration(string username, string userEmail)
        {
            SendGrid message = SendGrid.GetInstance();

            foreach (string email in AdministratorPrivateEmails)
            {
                message.AddTo(email);
            }
            message.From    = new MailAddress(SystemFromEmail);
            message.Subject = "VTS Automonitoring - new User has registered";
            message.Html    = String.Format("<p>Username: {0}</p> \r\n User email: {1}", username, userEmail);
            SMTP transport = SMTP.GetInstance(SendGridCredentials);

            transport.Deliver(message);
        }
示例#9
0
        public static void NotifySystemAboutUnrecognizedData(Stream dataStream)
        {
            SendGrid message = SendGrid.GetInstance();

            foreach (string email in AdministratorPrivateEmails)
            {
                message.AddTo(email);
            }
            message.From    = new MailAddress(SystemFromEmail);
            message.Subject = "VTS Automonitoring - Unrecognized data uploaded";
            message.Html    = String.Format("<p>Unrecognized data has been uploaded by someone.</p>");
            message.AddAttachment(dataStream, "UnrecognizedData.uvts");
            SMTP transport = SMTP.GetInstance(SendGridCredentials);

            transport.Deliver(message);
        }
        public void TestGetRcpts()
        {
            var foo = new Mock <IHeader>();
            var sg  = new SendGrid(foo.Object);

            sg.AddTo("*****@*****.**");
            sg.AddCc("*****@*****.**");
            sg.AddBcc("*****@*****.**");
            sg.AddBcc("*****@*****.**");

            var rcpts = sg.GetRecipients();

            Assert.AreEqual("*****@*****.**", rcpts.First(), "getRecipients check To");
            Assert.AreEqual("*****@*****.**", rcpts.Skip(1).First(), "getRecipients check Cc");
            Assert.AreEqual("*****@*****.**", rcpts.Skip(2).First(), "getRecipients check Bcc");
            Assert.AreEqual("*****@*****.**", rcpts.Skip(3).First(), "getRecipients check Bcc x2");
        }
示例#11
0
        public static void SendEmail(ApiServices services, Job job, string aadObjectId, IAadHelperProvider aadHelperProvider)
        {
            var    htmlContent  = GetJobDetailsInHTML(job);
            string accessToken  = aadHelperProvider.GetAccessToken();
            string agentName    = aadHelperProvider.GetUserDisplayName(aadObjectId, accessToken);
            string managerEmail = aadHelperProvider.GetManagerEmail(aadObjectId, accessToken);

            if (managerEmail == null)
            {
                // No e-mail (possibly running locally)
                return;
            }

            try
            {
                // Read values from service app settings
                string fromEmailId       = services.Settings["SendGridFromEmailId"];
                string fromEmailUserName = services.Settings["SendGridFromEmailUserName"];
                string sendGridUserName  = services.Settings["SendGridUserName"];
                string sendGridPassword  = services.Settings["SendGridPassword"];

                if (string.IsNullOrEmpty(fromEmailId) || string.IsNullOrEmpty(fromEmailUserName) ||
                    string.IsNullOrEmpty(sendGridUserName) || string.IsNullOrEmpty(sendGridPassword))
                {
                    services.Log.Warn("SendGrid is not properly configured, skipping sending e-mail.");
                    return;
                }

                SendGrid jobCompleteEmailMessage = SendGrid.GetInstance();
                jobCompleteEmailMessage.AddTo(managerEmail);
                jobCompleteEmailMessage.From    = new MailAddress(fromEmailId, fromEmailUserName);
                jobCompleteEmailMessage.Subject = "Job Complete Report from:" + agentName;
                jobCompleteEmailMessage.Html    = htmlContent;

                var credentials = new NetworkCredential(sendGridUserName, sendGridPassword);

                // Create a REST transport for sending email.
                var transportREST = Web.GetInstance(credentials);
                transportREST.Deliver(jobCompleteEmailMessage);
                services.Log.Info("Job complete email sent for jobId: " + job.Id);
            }
            catch (Exception ex)
            {
                services.Log.Error("Error sending email: " + ex.Message);
            }
        }
示例#12
0
        public static void NotifyAdminAboutVehicleAssociationWithUser(
            string modelName, string vin, string userLogin, long userId)
        {
            SendGrid message = SendGrid.GetInstance();

            foreach (string email in AdministratorPrivateEmails)
            {
                message.AddTo(email);
            }
            message.From    = new MailAddress(SystemFromEmail);
            message.Subject = "VTS Automonitoring - Vehicle has been associated to User";
            message.Html    = String.Format("<p>Model: {1}</p> \r\n Vin: {0} \r\n User Login: {2} \r\n User ID: {3}",
                                            vin, modelName, userLogin, userId);
            SMTP transport = SMTP.GetInstance(SendGridCredentials);

            transport.Deliver(message);
        }
示例#13
0
        public void SendMail(string fromemail, string fromdisplay, string to, string subject, string body)
        {
            try
            {
                SendGrid myMessage = SendGrid.GetInstance();

                myMessage.From    = new MailAddress(fromemail, fromdisplay);
                myMessage.Subject = subject;

                myMessage.AddTo(to);
                myMessage.Html = body;

                SendByWeb(myMessage);
            }
            catch
            {
            }
        }
示例#14
0
        public void Send(IEmailMessage message)
        {
            SendGrid myMessage = SendGrid.GetInstance();

            myMessage.AddTo(message.To);
            myMessage.From    = new MailAddress(message.From, message.FromName);
            myMessage.Subject = message.Subject;
            myMessage.Html    = message.Body;

            // Create credentials, specifying your user name and password.
            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["SendGridUsername"], ConfigurationManager.AppSettings["SendGridPassword"]);

            // Create an SMTP transport for sending email.
            var transportSMTP = SMTP.GetInstance(credentials);

            // Send the email.
            transportSMTP.Deliver(myMessage);
        }
示例#15
0
        public static void NotifyClientAboutRegistration(string email,
                                                         string newClientLogin, string newClientPassword)
        {
            string registrationMessage = String.Format(
                EmailingStringsProvider.GetString("ClientRegistrationNotification"),
                newClientLogin, newClientPassword);
            SendGrid message = SendGrid.GetInstance();

            message.AddTo(email);
            foreach (string admEmail in AdministratorPrivateEmails)
            {
                message.AddBcc(admEmail);
            }
            message.From    = new MailAddress(SystemFromEmail);
            message.Subject = "VTS Automonitoring - Доступ к системе";
            message.Html    = registrationMessage;
            SMTP transport = SMTP.GetInstance(SendGridCredentials);

            transport.Deliver(message);
        }
示例#16
0
        private static void window_onClosed(object sender, ClosedArgs args)
        {
            _gsTask.Wait();

            SendGrid mail = SendGrid.GetInstance();

            mail.AddTo(args.EmailAddress);
            mail.From    = new MailAddress("*****@*****.**", "8to18, Inc.");
            mail.Subject = "Your Printout From ADAssist";
            mail.Text    = "Your printout from ADAssist is attached.";
            mail.AddAttachment(_printerOutputFullPath);

            var credentials  = new NetworkCredential("8to18media", "YpiRBTzEfOyszKOGcRTZ");
            Web transportWeb = Web.GetInstance(credentials);

            transportWeb.Deliver(mail);

            File.Delete(_printerOutputFullPath);
            _printerOutputFullPath = string.Empty;
        }
示例#17
0
        public static void NotifyClientAboutVehicleAssociation(
            string clientEmail,
            string vehicleManufacturer,
            string vehicleModel,
            string vehicleVin)
        {
            string associationMessage = String.Format(
                EmailingStringsProvider.GetString("ClientVehicleAssociationNotification"),
                vehicleManufacturer, vehicleModel, vehicleVin);
            SendGrid message = SendGrid.GetInstance();

            message.AddTo(clientEmail);
            foreach (string admEmail in AdministratorPrivateEmails)
            {
                message.AddBcc(admEmail);
            }
            message.From    = new MailAddress(SystemFromEmail);
            message.Subject = "VTS Automonitoring - данные по машине";
            message.Html    = associationMessage;
            SMTP transport = SMTP.GetInstance(SendGridCredentials);

            transport.Deliver(message);
        }
        private void AddSubscribersInfo(SG.SendGridMessage message, IMessageJobRequest messageJob, IEnumerable<ISubscriberResponse> subscribers)
        {
            IEnumerable<string> replacementTags = this.GetReplacementTags(messageJob);

            // Creating Dictionary<string, List<string>> that will contain the replacement tag like {|Subscriber.Name|} and custom headers
            // like {|Subscriber.ResolveKey|} as keys. The value will be the list of per subscriber values in the same order as the list of 
            // emails to send to.
            var substitutions = this.InitializeSubstitutions(replacementTags, messageJob.CustomMessageHeaders);

            // Filling in the substitutions data structure with per subscriber values.
            foreach (var subscriber in subscribers)
            {
                // TODO: validate subscribers email addresses
                // TODO: add email + recipient name as TO address.
                message.AddTo(subscriber.Email);

                var subscriberPropertiesAsDict = subscriber.ToDictionary();
                this.CalculateSubstitutions(substitutions, subscriberPropertiesAsDict);
            }

            // Adding the constructed substitutions in the SendGrid message.
            foreach (var substitutionPair in substitutions)
            {
                message.AddSubstitution(substitutionPair.Key, substitutionPair.Value);
            }
        }