public ActionResult RequestPasswordResetConfirmation(string email)
        {
            var user = UserRepository.GetUserByNameOrEmail(email);

            if (user != null)
            {
                var myMessage = SendGrid.GetInstance();
                myMessage.AddTo(user.Email);
                myMessage.From    = new MailAddress("*****@*****.**", "Mittagessen Service");
                myMessage.Subject = "Mittagessen Passwort zurücksetzen";
                var passwordResetString = PasswordResetHelper.EncryptString(user.Email);
                myMessage.Html = string.Format(MAIL_TEMPLATE,
                                               Url.Action("ResetPassword", "Account", null, Request.Url.Scheme),
                                               HttpUtility.UrlEncode(passwordResetString));

                // 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);
            }
            return(View("RequestPasswordResetConfirmation", user));
        }
Beispiel #2
0
        private static void SendUsingSendGrid(string[] mailingList, IMessage message)
        {
            //TODO: add sending logic here
            // Setup the email properties.
            var from = new MailAddress(message.ReplyTo);
            var to   = new MailAddress[mailingList.Length];

            for (int i = 0; i < mailingList.Length; i++)
            {
                to[i] = new MailAddress(mailingList[i]);
            }
            var cc      = new MailAddress[] { };
            var bcc     = new MailAddress[] { };
            var subject = message.Subject;
            var html    = message.Body.Replace(Environment.NewLine, "<br/>") + "<br/>" + message.Link;

            // Create an email, passing in the the eight properties as arguments.
            SendGrid myMessage = SendGrid.GetInstance(from, to, cc, bcc, subject, html, null);

            var username = WebConfigurationManager.AppSettings["SendGridLogin"];
            var pswd     = WebConfigurationManager.AppSettings["SendGridPassword"];

            var credentials = new NetworkCredential(username, pswd);


            var transportSMTP = SMTP.GetInstance(credentials);


            transportSMTP.Deliver(myMessage);
        }
        /// <summary>
        /// SendMailBySendGrid
        /// this function is used for sending mail vai SendGrid
        /// the main input  parameter is :
        ///<add key="host" value="smtp.sendgrid.net" />
        /// <add key="port" value="25" />
        /// <add key="username" value="socioboard"/>
        /// <add key="fromemail" value="*****@*****.**"/>
        /// <add key="password" value="xyz" />
        ///<add key="tomail" value="*****@*****.**" />
        ///
        /// its return : success if mail send else return string.Empty;
        ///
        /// </summary>
        /// <param name="Host"></param>
        /// <param name="port"></param>
        /// <param name="from"></param>
        /// <param name="passsword"></param>
        /// <param name="to"></param>
        /// <param name="bcc"></param>
        /// <param name="cc"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="sendgridUserName"></param>
        /// <param name="sendgridPassword"></param>
        /// <returns></returns>

        public string SendMailBySendGrid(string Host, int port, string from, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName, string sendgridPassword)
        {
            string sendMailBySendGrid = string.Empty;

            try
            {
                var myMessage = SendGridMail.SendGrid.GetInstance();
                myMessage.From = new System.Net.Mail.MailAddress(from);
                myMessage.AddTo(to);
                myMessage.Subject = subject;

                //Add the HTML and Text bodies
                myMessage.Html = body;
                //myMessage.Text = "Hello World plain text!";
                var username = sendgridUserName;
                var pswd     = sendgridPassword;

                var credentials = new System.Net.NetworkCredential(username, pswd);

                var transportWeb = SMTP.GetInstance(credentials);

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

                sendMailBySendGrid = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            return(sendMailBySendGrid);
        }
Beispiel #4
0
        /// <summary>
        /// Send a simple HTML based email
        /// </summary>
        public void SimpleHTMLEmail()
        {
            //create a new message object
            var message = Mail.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Html = "<html><p>Hello</p><p>World</p></html>";

            //set the message subject
            message.Subject = "Hello World HTML Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //send the mail
            transportInstance.DeliverAsync(message);
        }
Beispiel #5
0
        /// <summary>
        /// The Footer App will insert a custom footer at the bottom of the text and HTML bodies.
        /// http://docs.sendgrid.com/documentation/apps/footer/
        /// </summary>
        public void EnableFooterEmail()
        {
            //create a new message object
            var message = Mail.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            var timestamp = DateTime.Now.ToString("HH:mm:ss tt");

            message.Html  = "<p style='color:red';>Hello World</p>";
            message.Html += "<p>Sent At : " + timestamp + "</p>";

            message.Text = "Hello World plain text";

            //set the message subject
            message.Subject = "Hello World Footer Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //Enable Footer
            message.EnableFooter("PLAIN TEXT FOOTER", "<p color='blue'>HTML FOOTER TEXT</p>");

            //send the mail
            transportInstance.DeliverAsync(message);
        }
Beispiel #6
0
    public void SimpleEmail(string subject, string messageToSend)
    {
        //create a new message object
        var message = SendGrid.GetInstance();

        //set the message recipients
        foreach (string recipient in _to)
        {
            message.AddTo(recipient);
        }

        //set the sender
        message.From = new MailAddress(_from);

        //set the message body
        message.Html = messageToSend;

        //set the message subject
        message.Subject = subject;

        //create an instance of the SMTP transport mechanism
        var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

        //send the mail
        transportInstance.Deliver(message);
    }
Beispiel #7
0
        /// <summary>
        /// Add automatic unsubscribe links to the bottom of emails.
        /// http://docs.sendgrid.com/documentation/apps/subscription-tracking/
        /// </summary>
        public void EnableUnsubscribeEmail()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Html = "This is the HTML body";

            message.Text = "This is the plain text body";

            //set the message subject
            message.Subject = "Hello World Unsubscribe Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //enable spamcheck
            //or optionally, you can specify 'replace' instead of the text and html in order to
            //place the link wherever you want.
            message.EnableUnsubscribe("Please click the following link to unsubscribe: <% %>", "Please click <% here %> to unsubscribe");

            //send the mail
            transportInstance.Deliver(message);
        }
Beispiel #8
0
        /// <summary>
        /// This feature wraps an HTML template around your email content.
        /// This can be useful for sending out newsletters and/or other HTML formatted messages.
        /// hhttp://docs.sendgrid.com/documentation/apps/email-templates/
        /// </summary>
        public void EnableBypassListManagementEmail()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            var timestamp = DateTime.Now.ToString("HH:mm:ss tt");

            message.Html  = "<p style='color:red';>Hello World</p>";
            message.Html += "<p>Sent At : " + timestamp + "</p>";

            message.Text = "Hello World plain text";

            //set the message subject
            message.Subject = "Hello World Bypass List Management Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //enable bypass list management
            message.EnableBypassListManagement();

            //send the mail
            transportInstance.Deliver(message);
        }
Beispiel #9
0
        /// <summary>
        /// The Spam Checker filter, is useful when your web application allows your end users
        /// to create content that is then emailed through your SendGrid account.
        /// http://docs.sendgrid.com/documentation/apps/spam-checker-filter/
        /// </summary>
        public void EnableSpamCheckEmail()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            var timestamp = DateTime.Now.ToString("HH:mm:ss tt");

            message.Html  = "<p style='color:red';>VIAGRA!!!!!! Viagra!!! CHECKOUT THIS VIAGRA!!!! MALE ENHANCEMENT!!! </p>";
            message.Html += "<p>Sent At : " + timestamp + "</p>";

            //set the message subject
            message.Subject = "WIN A MILLION DOLLARS TODAY! WORK FROM HOME! A NIGERIAN PRINCE WANTS YOU!";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //enable spamcheck
            message.EnableSpamCheck();

            //send the mail
            transportInstance.Deliver(message);
        }
        /// <summary>
        /// Sends the email.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns><c>true</c> if email sent succesfully, <c>false</c> otherwise.</returns>
        public bool SendEmail(IEmailMessage message)
        {
            if (message == null)
            {
                return(false);
            }

            //Smtp settings ?? is it OK to read setting directly here from config?
            var smtp = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");

            // Create the email object first, then add the properties.
            var eMessage = SendGrid.GetInstance();

            eMessage.From = !string.IsNullOrEmpty(message.From) ? new MailAddress(message.From) : new MailAddress(smtp.From);

            // Add multiple addresses to the To field.
            eMessage.AddTo(message.To);

            eMessage.Subject = message.Subject;

            //Add the HTML and Text bodies
            eMessage.Html = message.Html;
            eMessage.Text = message.Text;

            //Add attachments
            if (message.Attachments != null && message.Attachments.Count > 0)
            {
                foreach (var attachment in message.Attachments)
                {
                    try
                    {
                        using (var stream = new MemoryStream(attachment.Length))
                        {
                            stream.Write(attachment, 0, attachment.Length);
                            stream.Position = 0;
                            eMessage.AddAttachment(stream, "file_" + message.Attachments.IndexOf(attachment));
                        }
                    }
                    catch { return(false); }
                }
            }

            // Create credentials, specifying your user name and password.
            var credentials = new NetworkCredential(smtp.Network.UserName, smtp.Network.Password);

            // Create an SMTP transport for sending email.
            var transportSMTP = SMTP.GetInstance(credentials, smtp.Network.Host, smtp.Network.Port);

            // Send the email.
            try
            {
                transportSMTP.Deliver(eMessage);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Beispiel #11
0
        /// <summary>
        /// This feature tags the message with a specific tracking category, which will have aggregated stats
        /// viewable from your SendGrid account page.
        /// </summary>
        public void SetCategory()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Text = "Hello World";

            //set the message subject
            message.Subject = "Testing Categories";

            var category = "vipCustomers";

            message.SetCategory(category);

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //enable bypass list management
            message.EnableBypassListManagement();

            //send the mail
            transportInstance.Deliver(message);
        }
        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);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public void TestConstructor()
        {
            //Test on defaults of port 25 and
            var mock = new Mock <SMTP.ISmtpClient>();

            mock.SetupProperty(foo => foo.EnableSsl);
            var client      = mock.Object;
            var credentials = new NetworkCredential("username", "password");
            var test        = SMTP.GetInstance(client, credentials);

            mock.Verify(foo => foo.EnableSsl, Times.Never());

            mock = new Mock <SMTP.ISmtpClient>();
            mock.SetupProperty(foo => foo.EnableSsl);
            client      = mock.Object;
            credentials = new NetworkCredential("username", "password");
            test        = SMTP.GetInstance(client, credentials, port: SMTP.SslPort);
            mock.VerifySet(foo => foo.EnableSsl = true);

            mock = new Mock <SMTP.ISmtpClient>();
            mock.SetupProperty(foo => foo.EnableSsl);
            client      = mock.Object;
            credentials = new NetworkCredential("username", "password");
            try
            {
                test = SMTP.GetInstance(client, credentials, port: SMTP.TlsPort);
                Assert.Fail("should have thrown an unsupported port exception");
            }
            catch (NotSupportedException ex)
            {
                Assert.AreEqual("TLS not supported", ex.Message);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Send a simple Plain Text email
        /// </summary>
        public void SimplePlaintextEmail()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Text = "Hello World Plain Text";

            //set the message subject
            message.Subject = "Hello World Plain Text Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //send the mail
            transportInstance.Deliver(message);
        }
        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);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Enable The Gravatar Filter.
        /// Currently the filter generates a 1x1 pixel gravatar image.
        /// http://docs.sendgrid.com/documentation/apps/gravatar/
        /// </summary>
        public void EnableGravatarEmail()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Html = "<p style='color:red';>Hello World Gravatar Email</p>";

            //set the message subject
            message.Subject = "Hello World Gravatar Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //enable gravatar
            message.EnableGravatar();

            //send the mail
            transportInstance.Deliver(message);
        }
Beispiel #18
0
        private static void SendErrorNotification(int extensionId)
        {
            try
            {
                var smtpserver        = RoleEnvironment.GetConfigurationSettingValue(Constants.SmtpServer);
                var username          = RoleEnvironment.GetConfigurationSettingValue(Constants.SmtpUsername);
                var password          = RoleEnvironment.GetConfigurationSettingValue(Constants.SmtpPassword);
                var from              = RoleEnvironment.GetConfigurationSettingValue(Constants.EmailFrom);
                var emailTo           = RoleEnvironment.GetConfigurationSettingValue(Constants.EmailTo);
                var transportInstance = SMTP.GetInstance(new NetworkCredential(username, password), smtpserver);

                //create a new message object
                var message = SendGrid.GetInstance();

                //set the message recipients
                message.AddTo(emailTo);

                //set the sender
                message.From = new MailAddress(from);

                //set the message body
                message.Html = string.Format("<html><p>Hello Nathan,</p><p>While processing this ({0}) package, I encountered an error!</p>"
                                             + "<p>Best regards, <br />EVS</p></html>", extensionId);

                //set the message subject
                message.Subject = "EVS has encountered an error.";

                //send the mail
                transportInstance.Deliver(message);
            }
            catch (Exception exc)
            {
                Trace.TraceError("Error while sending error notification.", exc.Message);
            }
        }
Beispiel #19
0
        /// <summary>
        /// The Footer App will insert a custom footer at the bottom of the text and HTML bodies.
        /// http://docs.sendgrid.com/documentation/apps/google-analytics/
        /// </summary>
        public void EnableGoogleAnalytics()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            var timestamp = DateTime.Now.ToString("HH:mm:ss tt");

            message.Html  = "<p style='color:red';>Hello World</p>";
            message.Html += "<p>Sent At : " + timestamp + "</p>";
            message.Html += "Checkout my page at <a href=\"http://microsoft.com\">Microsoft</a>";

            message.Text = "Hello World plain text";

            //set the message subject
            message.Subject = "Hello World Footer Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //enable Google Analytics
            message.EnableGoogleAnalytics("SendGridTest", "EMAIL", "Sendgrid", "ad-one", "My SG Campaign");

            //send the mail
            transportInstance.Deliver(message);
        }
Beispiel #20
0
        /// <summary>
        /// Point the urls to Sendgrid Servers so that the clicks can be logged before
        /// being directed to the appropriate link
        /// http://docs.sendgrid.com/documentation/apps/click-tracking/
        /// </summary>
        public void EnableClickTrackingEmail()
        {
            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            foreach (string recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            var timestamp = DateTime.Now.ToString("HH:mm:ss tt");

            message.Html  = "<p style='color:red';>Hello World HTML </p> <a href='http://microsoft.com'>Checkout Microsoft!!</a>";
            message.Html += "<p>Sent At : " + timestamp + "</p>";

            message.Text = "hello world http://microsoft.com";

            //set the message subject
            message.Subject = "Hello World Click Tracking Test";

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

            //enable clicktracking
            message.EnableClickTracking(false);

            //send the mail
            transportInstance.Deliver(message);
        }
        private static void SendMail(string fileId, string email)
        {
            var extensionOutput = EVSAppController.Controllers.ExtensionController.GetExtension(fileId);

            var smtpserver = RoleEnvironment.GetConfigurationSettingValue(Constants.SmtpServer);
            var username   = RoleEnvironment.GetConfigurationSettingValue(Constants.SmtpUsername);
            var password   = RoleEnvironment.GetConfigurationSettingValue(Constants.SmtpPassword);
            var from       = RoleEnvironment.GetConfigurationSettingValue(Constants.EmailFrom);
            var emailTo    = RoleEnvironment.GetConfigurationSettingValue(Constants.EmailTo);

            //create a new message object
            var message = SendGrid.GetInstance();

            //set the message recipients
            message.AddTo(email);
            message.AddBcc(emailTo);

            //set the sender
            message.From = new MailAddress(from);

            //set the message body
            message.Html = BuildEmailBody(extensionOutput);

            //set the message subject
            message.Subject = "EVS: Review your verification results";

            //build attachments
            var filename = extensionOutput.OriginalFileName + "_EVS_Results";
            var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            var    xlsxFormatter    = new ExtensionMessageXlsxFormatter();
            var    xlsxFileLocation = tempPath + filename + ".xlsx";
            Stream xlsxFileStream   = File.Create(xlsxFileLocation);

            xlsxFormatter.WriteToStream(extensionOutput.ExtensionMessages, xlsxFileStream);
            message.AddAttachment(xlsxFileLocation);

            var    csvFormatter    = new ExtensionMessageCsvFormatter();
            var    csvFileLocation = tempPath + filename + ".csv";
            Stream csvFileStream   = File.Create(csvFileLocation);

            csvFormatter.WriteToStream(extensionOutput.ExtensionMessages, csvFileStream);
            message.AddAttachment(csvFileLocation);

            var    xmlFormatter    = new ExtensionMessageXmlFormatter();
            var    xmlFileLocation = tempPath + filename + ".xml";
            Stream xmlFileStream   = File.Create(xmlFileLocation);

            xmlFormatter.WriteToStream(extensionOutput.ExtensionMessages, xmlFileStream);
            message.AddAttachment(xmlFileLocation);

            //create an instance of the SMTP transport mechanism
            var transportInstance = SMTP.GetInstance(new NetworkCredential(username, password), smtpserver);

            //send the mail
            transportInstance.Deliver(message);
        }
        public void Send(IMailMessage message)
        {
            var  hostSettings = hostSettingsProvider.GetSettings();
            var  credentials  = new NetworkCredential(hostSettings.Username, hostSettings.Password);
            SMTP instance     = SMTP.GetInstance(credentials, hostSettings.Host, hostSettings.Port);

            // don't like this, but will do for now
            var sendGridMessageWrapper = (SendGridMessageWrapper)message;

            instance.Deliver(sendGridMessageWrapper.SendGrid);
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            #region 发送邮件
            SMTP smtp = SMTP.GetInstance("smtp-mail.outlook.com", 587, "*****@*****.**", "111qqq!!!W");
            smtp.SendMail("*****@*****.**", "*****@*****.**", "Test", "Test");
            #endregion

            //StaffManager.GetInstance().Import();
            Console.WriteLine("全部结束");
            Console.ReadKey();
        }
Beispiel #24
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);
        }
Beispiel #25
0
        public void Send <T>(string to, string templateName, string subject, T data)
        {
            var mail          = Mail.GetInstance();
            var transportSMTP = SMTP.GetInstance(this.credentials);
            var template      = Razor.Resolve <T>(templateName, data);
            var context       = new ExecuteContext();
            var message       = template.Run(context);

            mail.From    = new MailAddress("*****@*****.**");
            mail.Subject = subject;
            mail.AddTo(to);
            mail.Html = message;

            transportSMTP.Deliver(mail);
        }
Beispiel #26
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);
        }
Beispiel #27
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);
        }
Beispiel #28
0
        public static async Task SendEmail(EmailInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (info.From == null || info.To == null || info.To.Count < 1)
            {
                throw new ArgumentException("From or To values are missing", "emailInformation");
            }

            string userName     = CloudConfigurationManager.GetSetting("SendGridUsername");
            string password     = CloudConfigurationManager.GetSetting("SendGridPassword");
            SMTP   smtpInstance = SMTP.GetInstance(new NetworkCredential(userName, password), port: 587);

            IMail mail = Mail.GetInstance();

            mail.From    = new MailAddress(info.From, info.FromDisplayName);
            mail.Subject = info.Subject;
            foreach (string to in info.To)
            {
                mail.AddTo(to);
            }

            mail.DisableGoogleAnalytics();
            if (!string.IsNullOrEmpty(info.HtmlBody))
            {
                mail.Html = info.HtmlBody;
            }

            if (!string.IsNullOrEmpty(info.TextBody))
            {
                mail.Text = info.TextBody;
            }

            if (!string.IsNullOrEmpty(info.ReplyTo))
            {
                mail.ReplyTo = new[] { new MailAddress(info.ReplyTo) };
            }

            if (!string.IsNullOrEmpty(info.Category))
            {
                mail.SetCategory(info.Category);
            }

            await smtpInstance.DeliverAsync(mail);
        }
Beispiel #29
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);
        }
Beispiel #30
0
        public void SendResetPasswordEmail(string memberEmail, string resetGUID)
        {
            //Send a reset email to member
            // Create the email object first, then add the properties.
            var myMessage = SendGrid.GetInstance();

            // Add the message properties.
            myMessage.From = new MailAddress(EmailFromAddress);

            //Send to the member's email address
            myMessage.AddTo(memberEmail);

            //Subject
            myMessage.Subject = "Umb Jobs - Reset Your Password";

            //Reset link
            string baseURL  = HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty);
            var    resetURL = baseURL + "/reset-password?resetGUID=" + resetGUID;

            //HTML Message
            myMessage.Html = string.Format(
                "<h3>Reset Your Password</h3>" +
                "<p>You have requested to reset your password<br/>" +
                "If you have not requested to reste your password, simply ignore this email and delete it</p>" +
                "<p><a href='{0}'>Reset your password</a></p>",
                resetURL);


            //PlainText Message
            myMessage.Text = string.Format(
                "Reset your password" + Environment.NewLine +
                "You have requested to reset your password" + Environment.NewLine +
                "If you have not requested to reste your password, simply ignore this email and delete it" +
                Environment.NewLine + Environment.NewLine +
                "Reset your password: {0}",
                resetURL);

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

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

            // Send the email.
            transportSMTP.Deliver(myMessage);
        }