Beispiel #1
0
        static ALEXFWAuthentication()
        {
            _Config = WebConfigurationManager.OpenWebConfiguration("~");
            SystemWebSectionGroup system = (SystemWebSectionGroup)_Config.GetSectionGroup("system.web");

            IsEnabled = system.Authentication.Mode == AuthenticationMode.Forms;
            if (!IsEnabled)
            {
                return;
            }
            if (!_Config.AppSettings.Settings.AllKeys.Contains("ALEXFWAuthenticationKey"))
            {
                _Key = Guid.NewGuid().ToByteArray();
                _Config.AppSettings.Settings.Add("ALEXFWAuthenticationKey", Convert.ToBase64String(_Key));
                _Config.Save();
            }
            else
            {
                _Key = Convert.FromBase64String(_Config.AppSettings.Settings["ALEXFWAuthenticationKey"].Value);
            }
            CookieDomain = system.Authentication.Forms.Domain;
            CookieName   = system.Authentication.Forms.Name ?? "ALEXFWauth";
            CookiePath   = system.Authentication.Forms.Path;
            LoginUrl     = system.Authentication.Forms.LoginUrl;
            Timeout      = system.Authentication.Forms.Timeout;
        }
Beispiel #2
0
        private void DeclareSection(System.Configuration.Configuration config, string sectionName)
        {
            if (config.GetSectionGroup("userSettings") == null)
            {
                ConfigurationSectionGroup group2 = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", group2);
            }
            ConfigurationSectionGroup sectionGroup = config.GetSectionGroup("userSettings");

            if ((sectionGroup != null) && (sectionGroup.Sections[sectionName] == null))
            {
                ConfigurationSection section = new ClientSettingsSection {
                    SectionInformation = { AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser, RequirePermission = false }
                };
                sectionGroup.Sections.Add(sectionName, section);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get the specified section group type.
        /// </summary>
        /// <typeparam name="T">The configuration section group type.</typeparam>
        /// <param name="assemblyFilePath">The assembly file name and path assocciated with the configuration file.</param>
        /// <param name="sectionGroupName">The path name of the System.Configuration.ConfigurationSectionGroup to return.</param>
        /// <returns>The section group type.</returns>
        public static T GetSectionGroup <T>(string assemblyFilePath, string sectionGroupName) where T : System.Configuration.ConfigurationSectionGroup
        {
            // Get assembly configuration file.
            System.Configuration.Configuration config = Configuration(assemblyFilePath);

            // Get the section settings.
            T configSetting = config.GetSectionGroup(sectionGroupName) as T;

            // Return the configuration type.
            return(configSetting);
        }
Beispiel #4
0
        /// <summary>
        /// Get the specified application settings group.
        /// </summary>
        /// <param name="assemblyFilePath">The assembly file name and path assocciated with the configuration file.</param>
        /// <param name="sectionGroupName">The path name of the System.Configuration.ConfigurationSectionGroup to return.</param>
        /// <returns>Represents a grouping of related application settings sections within a configuration
        /// file. This class cannot be inherited.</returns>
        public static System.Configuration.ApplicationSettingsGroup GetApplicationSettings(string assemblyFilePath, string sectionGroupName)
        {
            // Get assembly configuration file.
            System.Configuration.Configuration config = Configuration(assemblyFilePath);

            // Get the section settings.
            System.Configuration.ApplicationSettingsGroup configSetting =
                config.GetSectionGroup(sectionGroupName) as System.Configuration.ApplicationSettingsGroup;

            // Return the configuration type.
            return(configSetting);
        }
Beispiel #5
0
        public ActionResult Create(utblGenEnquiry model)
        {
            System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup           settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
            //Create the SMTP Client
            SmtpClient client = new SmtpClient();

            client.Host        = settings.Smtp.Network.Host;
            client.Credentials = credential;
            client.Timeout     = 300000;
            client.EnableSsl   = false;
            if (ModelState.IsValid)
            {
                MailMessage   mail     = new MailMessage();
                StringBuilder mailbody = new StringBuilder();
                mail.From = new MailAddress(settings.Smtp.Network.UserName, "Brothers Tours & Travel");
                mail.To.Add(model.GuestEmailID);
                mail.To.Add("*****@*****.**");
                mail.Priority = MailPriority.High;
                mail.ReplyToList.Add("*****@*****.**");
                mail.Subject = "Enquiry Details";
                mailbody.Append("<b>Thank You for submitting your enquiry. Our Travel Agents with get in touch with you soon with answers to your enquiry.</b>");
                mailbody.Append("<h4>Enquiry Details</h4>");
                mailbody.Append("Email Address: " + model.GuestEmailID + "<br/>Contact No.: " + model.GuestMobileNo + "<br/>Enquiry : " + model.EnquiryDetails);
                mail.Body       = mailbody.ToString();
                mail.IsBodyHtml = true;
                DateTime Currdate    = DateTime.Today;
                string   tempdate    = Currdate.ToString("dd MMM yyyy");
                DateTime NewCurrDate = DateTime.ParseExact(tempdate, "dd MMM yyyy", CultureInfo.InvariantCulture);
                model.EnquiryDate   = NewCurrDate;
                model.EnquiryStatus = "Not Replied";
                try
                {
                    client.Send(mail);
                    var a = obj.Save(model);
                    return(Json(new { success = true, Message = 1 }));
                }
                catch (Exception)
                {
                    return(Json(new { success = true, Message = 0 }));
                }
            }
            return(PartialView("_pvEnquiry", model));
        }
Beispiel #6
0
        public ActionResult Reply(MstBookingReplyModel paramdata)
        {
            System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup           settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
            //Create the SMTP Client
            SmtpClient client = new SmtpClient();

            client.Host        = settings.Smtp.Network.Host;
            client.Credentials = credential;
            client.Timeout     = 300000;
            client.EnableSsl   = false;

            if (ModelState.IsValid)
            {
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress(settings.Smtp.Network.UserName, "Brothers Tours & Travel");
                mail.To.Add(paramdata.MstTourBook.ClientEmailID);
                mail.Priority = MailPriority.High;
                mail.Subject  = paramdata.MstMail.Subject;
                mail.Body     = paramdata.MstMail.MessageBody;
                mail.ReplyToList.Add("*****@*****.**");
                try
                {
                    client.Send(mail);
                    paramdata.MstTourBook.Status = "Replied";
                    dbBook.Save(paramdata.MstTourBook);
                    TempData["ErrMsg"] = 1;
                    return(RedirectToAction("list"));
                }
                catch (Exception ex)
                {
                    TempData["ErrMsg"] = 0;
                    return(RedirectToAction("list"));
                }
            }
            paramdata.MstTourBook = dbBook.GetBookingByID(paramdata.MstTourBook.BookingID);
            MstTourPackageDetailsModel pack   = new MstTourPackageDetailsModel();
            dalMstTourPackage          dbPack = new dalMstTourPackage();

            pack = dbPack.GetTourPackageDetailsByID(paramdata.MstTourBook.PackageID);
            ViewBag.PackageName = pack.PackageName;
            return(View(paramdata));
        }
        public bool SendEmail(utblTrnMessage Message)
        {
            System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup           settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
            //Create the SMTP Client
            SmtpClient client = new SmtpClient();

            client.Host        = settings.Smtp.Network.Host;
            client.Credentials = credential;
            client.Timeout     = 300000;
            client.EnableSsl   = false;

            MailMessage msg = new MailMessage();

            msg.From = new MailAddress(settings.Smtp.Network.UserName, "Sikkim Shagun ");
            //SmtpClient client = new SmtpClient();
            //client.Host = "smtp.zoho.com";
            //client.Port = 587;
            //client.DeliveryMethod = SmtpDeliveryMethod.Network;

            ////client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "spacebar321");// Enter seders User name and password
            //client.UseDefaultCredentials = false;
            //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "SSDG@123");// Enter seders User name and password
            //client.Timeout = 300000;
            //client.EnableSsl = true;
            //MailMessage msg = new MailMessage();
            //msg.From = new MailAddress("*****@*****.**", "Sikkim Service");
            msg.Body    = Message.MessageBody;
            msg.Subject = Message.MessageSubject;
            msg.To.Add(Message.SentTo);
            try
            {
                client.Send(msg);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        public ActionResult Reply(MstEnquiryReplyModel paramdata)
        {
            System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup           settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
            //Create the SMTP Client
            SmtpClient client = new SmtpClient();

            client.Host        = settings.Smtp.Network.Host;
            client.Credentials = credential;
            client.Timeout     = 300000;
            client.EnableSsl   = false;

            if (ModelState.IsValid)
            {
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress(settings.Smtp.Network.UserName, "Brothers Tours & Travel");
                mail.To.Add(paramdata.utblGenEnquiries.GuestEmailID);
                mail.Priority = MailPriority.High;
                mail.Subject  = paramdata.utblMails.Subject;
                mail.Body     = paramdata.utblMails.MessageBody;
                try
                {
                    client.Send(mail);
                    paramdata.utblGenEnquiries.EnquiryRepliedOn = DateTime.Now;
                    paramdata.utblGenEnquiries.EnquiryStatus    = "Replied";
                    paramdata.utblGenEnquiries.EnquiryRepliedBy = User.Identity.GetUserName().ToString();
                    db.Save(paramdata.utblGenEnquiries);
                    TempData["ErrMsg"] = 1;
                    return(RedirectToAction("list"));
                }
                catch (Exception ex)
                {
                    TempData["ErrMsg"] = 0;
                    return(RedirectToAction("list"));
                }
            }
            paramdata.utblGenEnquiries = db.GetEnquiryByID(paramdata.utblGenEnquiries.EnquiryID);
            return(View(paramdata));
        }
Beispiel #9
0
        private int SendEmailConfirmationToken(string userID, string subject, string email, string pass)
        {
            string code = UserManager.GenerateEmailConfirmationToken(userID);
            //string code = await UserManager.GenerateEmailConfirmationTokenAsync(userID);
            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = userID, code = code, area = "" }, protocol: Request.Url.Scheme);

            System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup           settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
            //Create the SMTP Client
            SmtpClient client = new SmtpClient();

            client.Host        = settings.Smtp.Network.Host;
            client.Credentials = credential;
            client.Timeout     = 300000;
            client.EnableSsl   = false;

            MailMessage mm = new MailMessage();

            mm.From = new MailAddress(settings.Smtp.Network.UserName, "Mount Pandim Tours & Travel");

            StringBuilder mailbody = new StringBuilder();

            mm.To.Add(email);
            mm.Priority = MailPriority.High;

            mm.Subject    = "Confirm your account";
            mm.Body       = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a> <br /> Login using the following details: <br /> User Name: " + email + "<br /> Password: " + pass;
            mm.IsBodyHtml = true;

            try
            {
                client.Send(mm);
                return(0);
            }
            catch (Exception ex)
            {
                return(1);
            }
        }
 static ComBoostAuthentication()
 {
     _Config = WebConfigurationManager.OpenWebConfiguration("~");
     SystemWebSectionGroup system = (SystemWebSectionGroup)_Config.GetSectionGroup("system.web");
     IsEnabled = system.Authentication.Mode == AuthenticationMode.Forms;
     if (!IsEnabled)
         return;
     if (!_Config.AppSettings.Settings.AllKeys.Contains("ComBoostAuthenticationKey"))
     {
         _Key = Guid.NewGuid().ToByteArray();
         _Config.AppSettings.Settings.Add("ComBoostAuthenticationKey", Convert.ToBase64String(_Key));
         _Config.Save();
     }
     else
     {
         _Key = Convert.FromBase64String(_Config.AppSettings.Settings["ComBoostAuthenticationKey"].Value);
     }
     CookieDomain = system.Authentication.Forms.Domain;
     CookieName = system.Authentication.Forms.Name ?? "comboostauth";
     CookiePath = system.Authentication.Forms.Path;
     LoginUrl = system.Authentication.Forms.LoginUrl;
     Timeout = system.Authentication.Forms.Timeout;
 }
        private bool SendEmail(string To, string From, string CC, string BCC, string Subject, string Body, ArrayList EmailAttechment)
        {
            //To = "*****@*****.**";
            //========== Find the config application path ==========//
            System.Configuration.Configuration Config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);

            //========== Find the mail setting from the web config file ==========//
            System.Net.Configuration.MailSettingsSectionGroup MailSettings = (System.Net.Configuration.MailSettingsSectionGroup)Config.GetSectionGroup("system.net/mailSettings");

            //========== Obtain the Network Credentials from the mailSettings section ==========//
            NetworkCredential Credential = new NetworkCredential(MailSettings.Smtp.Network.UserName, MailSettings.Smtp.Network.Password);

            //========== Create the SMTP Client ==========//
            System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient();

            //========== Assign the host address ==========//
            Client.Host = MailSettings.Smtp.Network.Host;

            //========== Assign the network credentials to the smtp client ==========//
            Client.Credentials = Credential;

            //========== Create the mail object ==========//
            System.Net.Mail.MailMessage ObjEmail = new System.Net.Mail.MailMessage();

            //========== Assign the values to the mail object ==========//
            if (From == "")
            {
                ObjEmail.From = new System.Net.Mail.MailAddress(From);
            }
            else
            {
                ObjEmail.From = new System.Net.Mail.MailAddress(From);
            }
            string[] _Str_Email_Address = To.Split(';');
            foreach (string item in _Str_Email_Address)
            {
                ObjEmail.To.Add(item);
            }
            if (BCC.Length != 0)
            {
                ObjEmail.Bcc.Add(BCC);
            }
            if (CC.Length != 0)
            {
                ObjEmail.CC.Add(CC);
            }
            ObjEmail.Subject    = Subject.Replace("\n", " ").Replace("\r", " ").Replace("\t", "");
            ObjEmail.IsBodyHtml = true;
            ObjEmail.Priority   = System.Net.Mail.MailPriority.Normal;
            ObjEmail.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnFailure;
            ObjEmail.Body = Body;


            //========== Check the email attachment for the email ==========//
            if (EmailAttechment != null && EmailAttechment.Count != 0)
            {
                for (int i = 0; i <= EmailAttechment.Count - 1; i++)
                {
                    System.Net.Mail.Attachment attachFile = new System.Net.Mail.Attachment(EmailAttechment[i].ToString());
                    ObjEmail.Attachments.Add(attachFile);
                }
            }
            try
            {
                Client.Send(ObjEmail);
            }
            catch (Exception Exc)
            {
                Exc.Message.ToString();
                return(false);
            }
            return(true);
        }
Beispiel #12
0
        static void Main()
        {
            try
            {
                DataPhilosophiaeSection dps = cm.GetSection("DataPhilosophiaeSection") as DataPhilosophiaeSection;
                if (dps != null)
                {
                    System.Console.WriteLine(dps.Stage.PathDir);
                    foreach (DataStoreElement ds in dps.DataStores)
                    {
                        System.Console.WriteLine(ds.Name);
                        System.Console.WriteLine(ds.LoadDefaultDatabaseOnly);
                        System.Console.WriteLine(ds.LoadSystemObjects);
                        System.Console.WriteLine(ds.WithFields);
                        if (string.IsNullOrWhiteSpace(ds.PathDir))
                        {
                            ds.PathDir = System.IO.Path.Combine(dps.Stage.PathDir, ds.Name);
                            cm.Save(System.Configuration.ConfigurationSaveMode.Minimal, true);
                        }
                        System.Console.WriteLine(ds.PathDir);
                    }
                }
                //DataStoreElement dse = new DataStoreElement(  );
                //cm.Save( System.Configuration.ConfigurationSaveMode.Minimal, false );
            }
            catch (System.Configuration.ConfigurationErrorsException ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            try
            {
                System.Configuration.ConnectionStringSettingsCollection settings = System.Configuration.ConfigurationManager.ConnectionStrings;
                if (settings != null)
                {
                    foreach (System.Configuration.ConnectionStringSettings cs in settings)
                    {
                        System.Console.WriteLine("            Name:" + cs.Name);
                        System.Console.WriteLine("    ProviderName:" + cs.ProviderName);
                        System.Console.WriteLine("ConnectionString:" + cs.ConnectionString);
                    }
                }
            }
            catch (System.Configuration.ConfigurationErrorsException ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            {
                DataPhilosophiaeSection dps = cm.GetSection("DataPhilosophiaeSection") as DataPhilosophiaeSection;
                DataStoreElement        ds  = dps.DataStores[0];
                System.Configuration.ConnectionStringSettingsCollection settings = System.Configuration.ConfigurationManager.ConnectionStrings;
                System.Configuration.ConnectionStringSettings           cs       = settings[ds.ConnectionStringName];
                //

                ActiveQueryBuilder.Core.SyntaxProviderList syntaxProviderList = new ActiveQueryBuilder.Core.SyntaxProviderList( );
                ActiveQueryBuilder.Core.SQLContext         sc = new ActiveQueryBuilder.Core.SQLContext( )
                {
                    SyntaxProvider   = new ActiveQueryBuilder.Core.AutoSyntaxProvider( ),
                    MetadataProvider = new ActiveQueryBuilder.Core.OLEDBMetadataProvider
                    {
                        Connection = new System.Data.OleDb.OleDbConnection( )
                        {
                            ConnectionString = cs.ConnectionString
                        }
                    }
                };
            }
            {
                DataPhilosophiaeSection dps = cm.GetSection("DataPhilosophiaeSection") as DataPhilosophiaeSection;
                DataStoreElement        ds  = dps.DataStores[0];
                System.Configuration.ConnectionStringSettingsCollection settings = System.Configuration.ConfigurationManager.ConnectionStrings;
                System.Configuration.ConnectionStringSettings           cs       = settings[ds.ConnectionStringName];
                //
                ActiveQueryBuilder.Core.SyntaxProviderList syntaxProviderList = new ActiveQueryBuilder.Core.SyntaxProviderList( );
                ActiveQueryBuilder.Core.SQLContext         sc = new ActiveQueryBuilder.Core.SQLContext( )
                {
                    SyntaxProvider   = new ActiveQueryBuilder.Core.SQLiteSyntaxProvider( ),
                    MetadataProvider = new ActiveQueryBuilder.Core.SQLiteMetadataProvider( )
                    {
                        Connection = new System.Data.SQLite.SQLiteConnection( )
                        {
                            ConnectionString = cs.ConnectionString
                        }
                    }
                };
                ActiveQueryBuilder.Core.MetadataLoadingOptions loadingOptions = sc.MetadataContainer.LoadingOptions;
                loadingOptions.LoadDefaultDatabaseOnly = ds.LoadDefaultDatabaseOnly == 1 ? true : false;
                loadingOptions.LoadSystemObjects       = ds.LoadSystemObjects == 1 ? true : false;
                //loadingOptions.IncludeFilter.Types = MetadataType.Field;
                //loadingOptions.ExcludeFilter.Schemas.Add(“dbo”);
                sc.MetadataContainer.LoadAll(ds.WithFields == 1 ? true : false);
            }

            //TunnelSection ts = System.Configuration.ConfigurationManager.GetSection( "TunnelSection" ) as TunnelSection;
            TunnelSection       ts                = cm.GetSection("TunnelSection") as TunnelSection;
            int                 count1            = ts.Tunnels.Count;
            HostConfigElement   hc                = ts.Tunnels[0];
            string              sSHServerHostname = hc.SSHServerHostname;
            string              username          = hc.Username;
            TunnelCollection    tunnels           = hc.Tunnels;
            int                 count2            = tunnels.Count;
            TunnelConfigElement tce               = tunnels[0];
            string              name              = tce.Name;
            int                 localPort         = tce.LocalPort;

            //ProductSettings productSettings = System.Configuration.ConfigurationManager.GetSection( "ProductSettings" ) as ProductSettings;
            //ConfigurationClassLoader x = System.Configuration.ConfigurationManager.GetSection( "Plugins" ) as ConfigurationClassLoader;

            //
            System.Configuration.ConfigurationSectionGroup      a        = cm.GetSectionGroup("DataStoreGroup");
            System.Configuration.ConfigurationSectionCollection sections = a.Sections;
            int count = sections.Count;

            System.Configuration.ConfigurationSection get = sections.Get(0);

            //         NewMethod( );
            //
            System.Windows.Forms.Application.EnableVisualStyles( );
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            System.Windows.Forms.Application.Run(new Form1( ));
        }
Beispiel #13
0
        private bool basicEnviar(String toEmail, String toName, string sCcAddress, string sCcAddressName, string sBccAddress, string subject, string body, IList <string> attachments, IDictionary <string, System.IO.Stream> attachments2, IDictionary <string, string> embeddedAttachments, bool sendBccCopy)
        {
            try
            {
                var toAddress = new MailAddress(toEmail, toName);
                var smtp      = new SmtpClient();
                var message   = new MailMessage()
                {
                    Subject = subject,
                    Body    = body
                };

                message.To.Add(toAddress);
                if (custom)
                {
                    smtp.Host                  = mailHost;
                    smtp.Port                  = mailPort;
                    smtp.EnableSsl             = mailSSL;
                    smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials           = new NetworkCredential(fromAddress.Address, fromPassword);
                    message.From               = fromAddress;
                }
                ;

                if (sCcAddress != null)
                {
                    message.CC.Add(new MailAddress(sCcAddress));
                }

                if (sBccAddress != null)
                {
                    message.Bcc.Add(new MailAddress(sBccAddress));
                }

                if (sendBccCopy)
                {
                    try
                    {
                        System.Configuration.Configuration configurationFile = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/web.config");
                        var mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as System.Net.Configuration.MailSettingsSectionGroup;
                        if (mailSettings != null)
                        {
                            string usernameSettings = mailSettings.Smtp.From;
                            message.Bcc.Add(new MailAddress(usernameSettings));
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                    }
                }

                message.IsBodyHtml = true;

                if (attachments != null && attachments.Count > 0)
                {
                    foreach (string s in attachments)
                    {
                        message.Attachments.Add(new Attachment(s));
                    }
                }
                if (attachments2 != null && attachments2.Count > 0)
                {
                    foreach (string s in attachments2.Keys)
                    {
                        message.Attachments.Add(new Attachment(attachments2[s], s));
                    }
                }
                if (embeddedAttachments != null && embeddedAttachments.Count > 0)
                {
                    AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, System.Net.Mime.MediaTypeNames.Text.Html);
                    foreach (string s in embeddedAttachments.Keys)
                    {
                        LinkedResource imagelink = new LinkedResource(embeddedAttachments[s], getMediaType(embeddedAttachments[s]));
                        imagelink.ContentId        = s;
                        imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
                        htmlView.LinkedResources.Add(imagelink);
                    }
                    message.AlternateViews.Add(htmlView);
                }

                ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };
                smtp.Send(message);
                return(true);
            }

            catch (Exception ex)
            {
                logger.Error(ex);
                return(false);
            }
        }
Beispiel #14
0
        /// <summary>
        /// 發送郵件函數
        /// </summary>
        /// <returns></returns>
        public string SetMail()
        {
            string RetMessage = "";

            try
            {
                System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
                MailSettingsSectionGroup           settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
                MailMessage msg         = new MailMessage();
                string      strFrom     = settings.Smtp.From;
                string      strFromName = "";
                string      strFromNo   = settings.Smtp.From;
                char[]      FromChars   = { '/' };
                char[]      ToChars     = { ';' };
                char[]      AttachChars = { ',', ';', '\t' };
                if (strFrom.IndexOf("/") > 0)
                {
                    string[] strFromNames = strFrom.Split(FromChars);
                    if (FromName == "")
                    {
                        strFromName = strFromNames[0];
                    }
                    else
                    {
                        strFromName = FromName;
                    }
                    strFromNo = strFromNames[1];
                }
                else
                {
                    if (FromName != "")
                    {
                        strFromName = FromName;
                    }
                }
                msg.From = new MailAddress(strFromNo, strFromName, Encoding.UTF8);

                if (To != "")
                {
                    if (To.Substring(To.Length - 1, 1) != ";")
                    {
                        To += ";";
                    }
                    string[] Tos       = To.Split(ToChars);
                    string   strTo     = "";
                    string   strToName = "";
                    foreach (string strTos in Tos)
                    {
                        strToName = "";
                        if (strTos != "")
                        {
                            strTo = strTos;
                            if (strTo.IndexOf("/") > 0)
                            {
                                string[] strToNames = strTo.Split(FromChars);
                                {
                                    strToName = strToNames[0];
                                    strTo     = strToNames[1];
                                }
                            }
                        }
                        msg.To.Add(new MailAddress(strTo, strToName, Encoding.UTF8));
                    }
                }

                if (CC != "")
                {
                    if (CC.Substring(CC.Length - 1, 1) != ";")
                    {
                        To += ";";
                    }
                    string[] CCs       = CC.Split(ToChars);
                    string   strCC     = "";
                    string   strCCName = "";
                    foreach (string strCCs in CCs)
                    {
                        strCCName = "";
                        if (strCCs != "")
                        {
                            strCC = strCCs;
                            if (strCC.IndexOf("/") > 0)
                            {
                                string[] strCCNames = strCC.Split(FromChars);
                                {
                                    strCCName = strCCNames[0];
                                    strCC     = strCCNames[1];
                                }
                            }
                        }
                        msg.CC.Add(new MailAddress(strCC, strCCName, Encoding.UTF8));
                    }
                }

                if (BCC != "")
                {
                    if (BCC.Substring(BCC.Length - 1, 1) != ";")
                    {
                        To += ";";
                    }
                    string[] BCCs       = BCC.Split(ToChars);
                    string   strBCC     = "";
                    string   strBCCName = "";
                    foreach (string strBCCs in BCCs)
                    {
                        strBCCName = "";
                        if (strBCCs != "")
                        {
                            strBCC = strBCCs;
                            if (strBCC.IndexOf("/") > 0)
                            {
                                string[] strBCCNames = strBCC.Split(FromChars);
                                {
                                    strBCCName = strBCCNames[0];
                                    strBCC     = strBCCNames[1];
                                }
                            }
                        }
                        msg.Bcc.Add(new MailAddress(strBCC, strBCCName, Encoding.UTF8));
                    }
                }

                if (Attachment != "")
                {
                    if (Attachment.Substring(Attachment.Length - 1, 1) != ";")
                    {
                        Attachment += ";";
                    }

                    string[] AttFile = Attachment.Split(AttachChars);
                    foreach (string strFile in AttFile)
                    {
                        if (strFile != "")
                        {
                            string strFileName = strFile;
                            if (strFile.Substring(0, 1) == "~")
                            {
                                strFileName = HttpContext.Current.Server.MapPath(strFileName);
                            }
                            msg.Attachments.Add(new Attachment(strFileName));
                        }
                    }
                }

                msg.Subject         = Subject;
                msg.SubjectEncoding = Encoding.UTF8;
                msg.Body            = Body;
                msg.IsBodyHtml      = IsBodyHtml;
                msg.BodyEncoding    = Encoding.UTF8;
                msg.Priority        = MailPriority.High;

                SmtpClient smtp = new SmtpClient(settings.Smtp.Network.Host, settings.Smtp.Network.Port);
                smtp.Credentials = new NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
                //smtp.UseDefaultCredentials = false;
                smtp.EnableSsl = EnabledSsl;
                smtp.Send(msg);
                msg.Dispose();
                smtp.Dispose();
            }
            catch (Exception ex)
            {
                RetMessage = ex.Message;
            }
            return(RetMessage);
        }
Beispiel #15
0
        public ActionResult BookingRequest(MstPackageGeneralViewModel model)
        {
            System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup           settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
            //Create the SMTP Client
            SmtpClient client = new SmtpClient();

            client.Host        = settings.Smtp.Network.Host;
            client.Credentials = credential;
            client.Timeout     = 300000;
            client.EnableSsl   = false;
            dalTourPackageBooking dbBook = new dalTourPackageBooking();

            model.MstPackageBooking.PackageID = model.MstTourPackage.PackageID;
            DateTime Arrdate       = model.MstPackageBooking.ArrivalDate;
            DateTime Departuredate = model.MstPackageBooking.DepartureDate;
            string   tempdt        = Arrdate.ToString("dd MMM yyyy");
            string   Deptdt        = Departuredate.ToString("dd MMM yyyy");

            model.MstPackageBooking.ArrivalDate   = DateTime.ParseExact(tempdt, "dd MMM yyyy", CultureInfo.InvariantCulture);
            model.MstPackageBooking.DepartureDate = DateTime.ParseExact(Deptdt, "dd MMM yyyy", CultureInfo.InvariantCulture);

            DateTime Currdate      = DateTime.Today;
            string   tempdate      = Currdate.ToString("dd MMM yyyy");
            string   Depdate       = Currdate.ToString("dd MMM yyyy");
            DateTime NewCurrDate   = DateTime.ParseExact(tempdate, "dd MMM yyyy", CultureInfo.InvariantCulture);
            DateTime DepartureDate = DateTime.ParseExact(Depdate, "dd MMM yyyy", CultureInfo.InvariantCulture);


            if (ModelState.IsValid)
            {
                MailMessage   mail     = new MailMessage();
                StringBuilder mailbody = new StringBuilder();
                mail.From = new MailAddress("*****@*****.**", "Pandim Tours & Travel");
                //mail.To.Add("*****@*****.**");
                mail.To.Add(model.MstPackageBooking.ClientEmailID);
                mail.Priority = MailPriority.High;
                mail.ReplyToList.Add("*****@*****.**");
                mail.CC.Add("*****@*****.**");
                mail.Subject = "Booking Request for Tour Package: " + model.MstTourPackage.PackageName;
                mailbody.AppendLine("Thank You for your Booking Request for the Tour Package: <b>" + model.MstTourPackage.PackageName + "</b>.<br/> We will get Back to you with further details as soon as possible.");
                string packdetails = MakeMailBody(model.MstTourPackage.PackageID);
                mailbody.Append(packdetails);
                mailbody.Append("<h4>Personal Details</h4>");
                mailbody.Append("Name: " + model.MstPackageBooking.ClientName + "<br/>Total number of people: " + model.MstPackageBooking.AdultPax + " Adults / " + model.MstPackageBooking.ChildPax + " Child / " + model.MstPackageBooking.InfantPax + " Infants.<br/>");
                mailbody.Append("Arrival Date: " + model.MstPackageBooking.ArrivalDate.ToString("dd MMM yyyy") + "<br/>Contact No: " + model.MstPackageBooking.ClientContactNo);
                mailbody.Append("Arrival Date: " + model.MstPackageBooking.DepartureDate.ToString("dd MMM yyyy"));
                mailbody.AppendLine("<br/>Requirement: " + model.MstPackageBooking.ClientRequirement);
                mailbody.Append("<br/>Please check your mail for regular updates from us.");
                mail.Body       = mailbody.ToString();
                mail.IsBodyHtml = true;
                try
                {
                    client.Send(mail);
                    model.MstPackageBooking.BookingDate = NewCurrDate;
                    model.MstPackageBooking.Status      = "Not Replied";
                    dbBook.Save(model.MstPackageBooking);
                    return(RedirectToAction("RequestSuccess", new { id = model.MstTourPackage.PackageID }));
                }
                catch (Exception)
                {
                    TempData["ErrMsg"] = 0;
                    return(RedirectToAction("TourPackageDetails", new { id = model.MstTourPackage.PackageID }));
                }
            }
            dalMstTourPackageActivity dbAct = new dalMstTourPackageActivity();
            dalTourPackageMap         dbMap = new dalTourPackageMap();

            model.MstTourPhotoList    = dbPhoto.MstTourPackagePhotoList(model.MstTourPackage.PackageID);
            model.MstTourPackage      = dbTour.MstTourPackageView(model.MstTourPackage.PackageID);
            model.MstTourActivityList = dbAct.MstTourPackageActivityList(model.MstTourPackage.PackageID);
            model.MstTourMap          = dbMap.GetTourMapByID(model.MstTourPackage.PackageID);

            return(View("TourPackageDetails", model));
        }
Beispiel #16
0
        public ActionResult Contact(ContactModel model)
        {
            if (ModelState.IsValid)
            {
                System.Configuration.Configuration config     = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
                MailSettingsSectionGroup           settings   = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
                System.Net.NetworkCredential       credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
                //Create the SMTP Client
                SmtpClient client = new SmtpClient();
                client.Host        = settings.Smtp.Network.Host;
                client.Credentials = credential;
                client.Timeout     = 300000;
                client.EnableSsl   = false;

                MailMessage   mail     = new MailMessage();
                StringBuilder mailbody = new StringBuilder();
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add("*****@*****.**");
                mail.Priority = MailPriority.High;

                mail.CC.Add("*****@*****.**");
                mail.Subject = "Message from Customer";
                mailbody.Append("Name: " + model.FirstName + " " + model.LastName + " Email: " + model.EmailAddress + " " + " " + " Message: " + model.Message);
                mailbody.Append("<br/>" + model.PhoneNumber);
                mail.Body       = mailbody.ToString();
                mail.IsBodyHtml = true;
                try
                {
                    client.Send(mail);
                    return(RedirectToAction("contact"));
                }
                catch (Exception ex)
                {
                    TempData["ErrMsg"] = 0;
                    return(RedirectToAction("contact"));
                }
            }
            return(View(model));
        }