Inheritance: System.Configuration.ConfigurationSectionGroup
    public void SendMail(string mailBody, string mailSubject)
    {
        // ------------------------------------------------------
        // MAIL SERVER SETTINGS (DONT' TOUCH THE CODE)
        // ------------------------------------------------------
        System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
        System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
        string      server  = settings.Smtp.Network.Host;
        int         port    = settings.Smtp.Network.Port;
        string      email   = settings.Smtp.Network.UserName;
        string      passkey = settings.Smtp.Network.Password;
        MailMessage objMail = new MailMessage();

        objMail.To.Add("*****@*****.**");
        objMail.To.Add("*****@*****.**");
        objMail.From = new MailAddress("*****@*****.**", "Giftstoindia24x7");
        //objMail.CC.Add("*****@*****.**");
        objMail.Subject    = "Error : " + mailSubject;
        objMail.Body       = mailBody;
        objMail.IsBodyHtml = true;
        objMail.Priority   = MailPriority.High;
        //objMail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
        try
        {
            SmtpClient client = new SmtpClient(server);
            client.UseDefaultCredentials = false;
            client.Credentials           = new NetworkCredential(email, passkey);
            client.Port = port;
            //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
            client.Send(objMail);
            //flag = true;
        }
        catch (SmtpException ex) {  }
    }
Exemple #2
0
        public ActionResult CreateComment(CreateCommentViewModel newComment)
        {
            var articleData = _dataContext.Articles.Where(article => article.Id == newComment.ArticleId).SingleOrDefault();

            MailSettingsSectionGroup GetMailSettings = new MailSettingsSectionGroup();
            var mailService = new MailService();

            var comment = new Comment
                              {
                                  Name = newComment.Name,
                                  Email = newComment.Email,
                                  Location = newComment.Location,
                                  Text = newComment.Text,
                                  ArticleId = newComment.ArticleId,
                                  PostDate = DateTime.UtcNow
                              };

            _dataContext.Comments.Add(comment);
            _dataContext.SaveChanges();

            newComment.Text = newComment.Text + "\\n Article Category: " + articleData.Category + "\\n Click here to moderate this comment: " + ConfigurationManager.AppSettings["siteURL"] + "/ManageComment/Detail/" + comment.CommentId;

            List<string> emailRecipients = new List<string>() { ConfigurationManager.AppSettings["CommentAlertEmail"] };
            try
            {
                mailService.Send(emailRecipients, "RFH: A new comment has been added for the article - " + articleData.Title, newComment.Text, null);
            }
            catch (Exception)
            {

            }

            return  RedirectToAction("Index", "Article", new { id = newComment.ArticleId});
        }
 /// <summary>
 /// test the smtp connection by sending a HELO command
 /// </summary>
 /// <param name="mailSettings"></param>
 /// <returns></returns>
 public static bool TestConnection(MailSettingsSectionGroup mailSettings)
 {
     if (mailSettings == null)
     {
         throw new ConfigurationErrorsException("The system.net/mailSettings configuration section group could not be read.");
     }
     return TestConnection(mailSettings.Smtp.Network.Host, mailSettings.Smtp.Network.Port);
 }
            /// <summary>
            /// test the smtp connection by sending a HELO command
            /// </summary>
            /// <param name="mailSettings"></param>
            /// <returns>Result of the testing connection</returns>
            public static bool TestConnection(MailSettingsSectionGroup mailSettings)
            {
                if (mailSettings == null)
                {
                    throw new ConfigurationErrorsException(Labels.CouldNotReadSmtpSettings);
                }

                return TestConnection(mailSettings.Smtp.Network.Host, mailSettings.Smtp.Network.Port);
            }
        private NotificationManager()
        {
            Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
            _mailSettings = configurationFile.GetSectionGroup(MAIL_SETTINGS_SECTION_GROUP_NAME) as MailSettingsSectionGroup;

            _smtpClient = new SmtpClient(_mailSettings.Smtp.Network.Host)
            {
                EnableSsl = _mailSettings.Smtp.Network.EnableSsl,
                Credentials = new NetworkCredential(_mailSettings.Smtp.Network.UserName, _mailSettings.Smtp.Network.Password)
            };
        }
Exemple #6
0
    protected void cmdSend_Click(object sender, EventArgs e)
    {
        string       sRequestTemplateFile = LegoWebSite.DataProvider.FileTemplateDataProvider.get_HtmlTemplateFile("RequestEmailTemplate");
        StreamReader sr      = new System.IO.StreamReader(sRequestTemplateFile);
        string       content = sr.ReadToEnd();

        sr.Close();
        content = content.Replace("[Sender]", this.txtSenderName.Text.Trim());
        content = content.Replace("[Phone]", this.txtSenderPhoneNumber.Text.Trim());
        content = content.Replace("[Email]", this.txtSenderEmail.Text.Trim());
        content = content.Replace("[Title]", this.txtRequestEmailSubject.Text.Trim());
        content = content.Replace("[Content]", this.txtRequestEmailBody.Text.Trim());
        content = content.Replace("[DateTime]", DateTime.Now.ToShortDateString());


        //Now we need to setup the mail message that will be sent
        //create the mailmessage object
        MailMessage message = new MailMessage();

        //set the bodyhtml to true so we can add html to our message
        message.IsBodyHtml = true;
        //set who the email is from, this should correspond to the email we setup
        //in the smtp settings earlier
        System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
        System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");


        message.From = new MailAddress(settings.Smtp.From);
        //send this message to the email destination
        message.To.Add(new MailAddress(drlistToEmailAddress.SelectedValue));
        //set the subject
        message.Subject = this.txtRequestEmailSubject.Text.Trim();
        //Set the body of our message
        message.Body = content;

        divSendRequest.Visible = false;
        divSendStatus.Visible  = true;

        try
        {
            //Send the message
            SmtpClient client = new SmtpClient();
            client.Send(message);
            litSendRequestStatus.Text = String.Format("<h3>{0}</h3>", Resources.strings.YourRequestHasBeenSent);
        }
        catch (Exception ex)
        {
            litSendRequestStatus.Text = "Error:" + ex.Message;
        }
    }
        private void LoadMailSettings()
        {
            InitSSConfig();

            string tmpConfigLeaf = Path.GetFileName(config.FilePath);
            string tmpConfigDir = Path.GetTempPath();
            fullPathTmpConfig = Path.Combine(tmpConfigDir, tmpConfigLeaf);

            initialMailSettings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
            FromTextBox.Text = initialMailSettings.Smtp.From;
            HostnameTextBox.Text = initialMailSettings.Smtp.Network.Host;
            PortTextBox.Text = initialMailSettings.Smtp.Network.Port.ToString();
            UsernameTextBox.Text = initialMailSettings.Smtp.Network.UserName;
            PasswordTextBox.Text = initialMailSettings.Smtp.Network.Password;
            DefaultCredsCheckBox.Checked = initialMailSettings.Smtp.Network.DefaultCredentials;
        }
Exemple #8
0
 public void Mail(string subject, string body, string MailTO)
 {
     System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
     System.Net.Configuration.MailSettingsSectionGroup settings = ((System.Net.Configuration.MailSettingsSectionGroup)(config.GetSectionGroup("system.net/mailSettings")));
     System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(settings.Smtp.Network.UserName, MailTO);
     mail.Body       = body;
     mail.Subject    = subject;
     mail.IsBodyHtml = true;
     System.Net.Mail.SmtpClient o = new System.Net.Mail.SmtpClient(settings.Smtp.Network.Host);
     o.Credentials = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
     try
     {
         o.Send(mail);
     }
     catch (Exception error)
     {
         HttpContext.Current.Response.Write("<table width=100%><tr><td Class='ErrorMsg' align=center width=100%>" + error.Message + "!</td></tr></table>");
     }
 }
Exemple #9
0
    protected void UpdateSettings_Click(object sender, EventArgs e)
    {
        anm_Utility dt    = new anm_Utility();
        Boolean     error = false;

        if ((txtSmtp.Text == dt.GetSetting("smtpserver")) && (txtUserMail.Text == dt.GetSetting("MailUser")) && (txtPswMail.Text == dt.GetSetting("MailPassword")) && (txtPort.Text == dt.GetSetting("port")))
        {
        }
        else
        {
            try
            {
                System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
                System.Net.Configuration.MailSettingsSectionGroup mailSection = config.GetSectionGroup("system.net/mailSettings") as System.Net.Configuration.MailSettingsSectionGroup;
                mailSection.Smtp.From             = txtemail.Text;
                mailSection.Smtp.Network.Host     = txtSmtp.Text;
                mailSection.Smtp.Network.UserName = txtUserMail.Text;
                mailSection.Smtp.Network.Password = txtPswMail.Text;
                int  mailPort = 25;
                bool isNum    = int.TryParse(txtPort.Text, out mailPort);
                if (isNum)
                {
                    mailSection.Smtp.Network.Port = mailPort;
                }
                else
                {
                    mailSection.Smtp.Network.Port = 25;
                }
                config.Save(ConfigurationSaveMode.Modified);
            }
            catch
            {
                Label11.Text    = GetGlobalResourceObject("language", "nopermupdwebconf").ToString();
                Label11.Visible = true;
                error           = true;
            }
        }
        int archivetype = 0;

        if (chkType1.Checked)
        {
            archivetype = 1;
        }
        if (chkType2.Checked)
        {
            archivetype = 2;
        }

        string        strConn      = ConfigurationManager.ConnectionStrings["anmcs"].ToString();
        SqlConnection myConnection = new SqlConnection(strConn);
        SqlCommand    command      = new SqlCommand();

        command.Connection = myConnection;
        command.Parameters.Add("@SiteName", SqlDbType.NVarChar).Value = txtsn.Text.ToString();
        Cache.Insert("SiteName", txtsn.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@SiteEmail", SqlDbType.NVarChar).Value = txtemail.Text.ToString();
        Cache.Insert("SiteEmail", txtemail.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@SiteUrl", SqlDbType.NVarChar).Value = txturl.Text.ToString();
        Cache.Insert("SiteUrl", txturl.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@Search", SqlDbType.Bit).Value = CheckBox4.Checked;
        Cache.Insert("SearchMenu", CheckBox4.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@Validator", SqlDbType.Bit).Value = CheckBox3.Checked;
        Cache.Insert("Validator", CheckBox3.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@Archive", SqlDbType.Bit).Value = CheckBox5.Checked;
        Cache.Insert("ArchiveMenu", CheckBox5.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@LastNews", SqlDbType.Bit).Value = CheckBox6.Checked;
        Cache.Insert("LastNews", CheckBox6.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@LastComments", SqlDbType.Bit).Value = CheckBox7.Checked;
        Cache.Insert("LastComments", CheckBox7.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@CaptchaNewUser", SqlDbType.Bit).Value = CheckBox8.Checked;
        Cache.Insert("CaptchaNewUser", CheckBox8.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@CaptchaComments", SqlDbType.Bit).Value = CheckBox10.Checked;
        Cache.Insert("CaptchaComments", CheckBox10.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@EmailConfirm", SqlDbType.Bit).Value = CheckBox9.Checked;
        Cache.Insert("EmailConfirm", CheckBox9.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@smtpserver", SqlDbType.NVarChar).Value = txtSmtp.Text.ToString();
        Cache.Insert("smtpserver", txtSmtp.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@MailUser", SqlDbType.NVarChar).Value = txtUserMail.Text.ToString();
        Cache.Insert("MailUser", txtUserMail.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@MailPassword", SqlDbType.NVarChar).Value = txtPswMail.Text.ToString();
        Cache.Insert("MailPassword", txtPswMail.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@port", SqlDbType.NVarChar).Value = txtPort.Text.ToString();
        Cache.Insert("port", txtPort.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@ViewNarticles", SqlDbType.Bit).Value = CheckBox1.Checked;
        Cache.Insert("ViewNarticles", CheckBox1.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@ArchiveType", SqlDbType.Int).Value = archivetype;
        Cache.Insert("ArchiveType", archivetype, null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@TagBox", SqlDbType.Bit).Value = CheckBox11.Checked;
        Cache.Insert("TagBox", CheckBox11.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@CaptchaType", SqlDbType.NVarChar).Value = DDcaptcha.SelectedValue;
        Cache.Insert("CaptchaType", DDcaptcha.SelectedValue.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@OnlineUsers", SqlDbType.Bit).Value = CheckBox12.Checked;
        Cache.Insert("OnlineUsers", CheckBox12.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        string banner = "";

        if (CheckBox2.Checked & FileUpload1.FileName.ToString() == "" & txtBanner.Text.ToString() != "")
        {
            banner = txtBanner.Text.ToString();
        }
        else if (CheckBox2.Checked & FileUpload1.FileName.ToString() != "")
        {
            anm_Utility ut           = new anm_Utility();
            string      filename     = FileUpload1.FileName;
            string      tempfileName = "";
            string      savePath     = Server.MapPath("~\\images\\");
            string      pathToCheck  = savePath + filename;
            if (System.IO.File.Exists(pathToCheck))
            {
                int counter = 2;
                while (System.IO.File.Exists(pathToCheck))
                {
                    tempfileName = counter.ToString() + filename;
                    pathToCheck  = savePath + tempfileName;
                    counter++;
                }
                filename = tempfileName;
            }
            FileUpload1.SaveAs(Server.MapPath("~\\images\\full_") + filename);
            int newWidth  = 0;
            int newHeight = 0;
            if (txtW.Text != "")
            {
                newWidth = Convert.ToInt32(txtW.Text);
            }
            if (txtH.Text != "")
            {
                newHeight = Convert.ToInt32(txtH.Text);
            }
            ut.GenerateImage(Server.MapPath("~\\images\\full_") + filename, Server.MapPath("~\\images\\") + filename, newWidth, newHeight, "", "", "jpeg", "Black", "Arial", 13, "br");

            banner = filename;
        }
        command.Parameters.Add("@Banner", SqlDbType.NVarChar).Value = banner;
        Cache.Insert("Banner", banner, null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);

        command.CommandText = "UPDATE anm_Settings SET SiteName=@SiteName,SiteEmail=@SiteEmail,SiteUrl=@SiteUrl,SearchMenu=@Search,Validator=@Validator,ArchiveMenu=@Archive,LastNews=@LastNews,LastComments=@LastComments,CaptchaNewUser=@CaptchaNewUser,CaptchaComments=@CaptchaComments,EmailConfirm=@EmailConfirm,smtpserver=@smtpserver,MailUser=@MailUser,MailPassword=@MailPassword,port=@port,Banner=@Banner,ViewNarticles=@ViewNarticles,ArchiveType=@ArchiveType,TagBox=@TagBox,CaptchaType=@CaptchaType,OnlineUsers=@OnlineUsers WHERE id=1";
        myConnection.Open();
        object accountNumber = command.ExecuteScalar();

        myConnection.Close();

        if (!error)
        {
            Response.Redirect("homepage.aspx");
        }
    }
 protected SmtpMailer()
 {
     _mailSettings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).GetSectionGroup("system.net/mailSettings")
                     as MailSettingsSectionGroup;
 }
 public static SmtpMailer Instance(Configuration configuration)
 {
     _mailSettings = configuration.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;
     return _instance ?? (_instance = new SmtpMailer());
 }
 public SmtpZsValidationProvider(MailSettingsSectionGroup mailSettings)
 {
     _mailSettings = mailSettings;
 }
 public ConfigMailerSettingsManager()
 {
     _mailSettings = (MailSettingsSectionGroup)ConfigurationManager.GetSection("system.net/mailSettings");
 }