private void AddContentAndSend(SendGrid myMessage)
        {
            try
            {
                var lunches = LunchRepository.GetLunchesForThisWeek().ToList();

                myMessage.From    = new MailAddress("*****@*****.**", "Mittagessen Service");
                myMessage.Subject = "Herzliche Einladung zum Mittagessen";
                myMessage.AddAttachment(GetImageFile(lunches[0].CookedMeal.ImageName), "dienstag.jpg");
                myMessage.AddAttachment(GetImageFile(lunches[1].CookedMeal.ImageName), "mittwoch.jpg");
                myMessage.AddAttachment(GetImageFile(lunches[2].CookedMeal.ImageName), "donnerstag.jpg");
                myMessage.Html = string.Format(MAIL_TEMPLATE,
                                               lunches[0].CookedMeal.Name, "cid:dienstag.jpg", GetImageUrl(lunches[0].CookedMeal.ImageName),
                                               lunches[1].CookedMeal.Name, "cid:mittwoch.jpg", GetImageUrl(lunches[1].CookedMeal.ImageName),
                                               lunches[2].CookedMeal.Name, "cid:donnerstag.jpg", GetImageUrl(lunches[2].CookedMeal.ImageName));

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

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

                // Send the email.
                transportSMTP.Deliver(myMessage);
            }
            catch (Exception e)
            {
                Logger.FatalException("Email exception occured", e);
            }
        }
        public void TestAddAttachment()
        {
            var foo = new Mock <IHeader>();
            var sg  = new SendGrid(foo.Object);

            sg.AddAttachment("pnunit.framework.dll");
            sg.AddAttachment("pnunit.framework.dll");
            //Assert.AreEqual(data.ContentStream, sg.Attachments.First().ContentStream, "Attach via path");
            //Assert.AreEqual(data.ContentStream, sg.Attachments.Skip(1).First().ContentStream, "Attach via path x2");

            sg = new SendGrid(foo.Object);
            //sg.AddAttachment(data);
            //sg.AddAttachment(data);
            //Assert.AreEqual(data.ContentStream, sg.Attachments.First().ContentStream, "Attach via attachment");
            //Assert.AreEqual(data.ContentStream, sg.Attachments.Skip(1).First().ContentStream, "Attach via attachment x2");

            sg = new SendGrid(foo.Object);
            //sg.AddAttachment(data.ContentStream, data.ContentType);
            //sg.AddAttachment(data.ContentStream, data.ContentType);
            //Assert.AreEqual(data.ContentStream, sg.Attachments.First().ContentStream, "Attach via stream");
            //Assert.AreEqual(data.ContentStream, sg.Attachments.Skip(1).First().ContentStream, "Attach via stream x2");
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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;
        }
        public string SendMailWithAttachment(string from, string passsword, string to, string bcc, string cc, string subject, string body, string file, string filename, string filetype, string sendgridUserName = "", string sendgridPassword = "")
        {
            string sendMailBySendGrid = string.Empty;

            try
            {
                //var smtp = new SmtpClient();
                //smtp.Port = 25;
                //smtp.Host = "smtp.sendgrid.net";
                using (Stream attachmentFileStream = new FileStream(file, FileMode.Open))
                {
                    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.AddAttachment(attachmentFileStream, filename + "." + filetype);

                    //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);
        }