コード例 #1
0
    protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        lblSucess.Text = "";
        var    dvEmail     = (OdsNewsletter.Select() as DataView);
        string strHost     = "tranlegroup.com";
        int    iPort       = 25;
        string strMailFrom = "*****@*****.**";
        string strPassword = "******";
        string strMailTo   = (from DataRowView drv in dvEmail select drv["Email"].ToString()).ToList <string>().Aggregate((a, b) => a + ',' + b);
        string strCC       = "";
        string strSubject  = txtSubject.Text.Trim();
        string strBody     = FCKEditorFix.Fix(txtBody.Content.Trim());
        bool   bEnableSsl  = false;

        TLLib.Common.SendMail(
            strHost,
            iPort,
            strMailFrom,
            strPassword,
            strMailTo,
            strCC,
            strSubject,
            strBody,
            bEnableSsl
            );

        lblSucess.Text = "Email has been send.";
    }
コード例 #2
0
    protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        lblSucess.Text = "";
        var fileMap = new ExeConfigurationFileMap()
        {
            ExeConfigFilename = Server.MapPath("~/config/app.config")
        };
        var config    = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
        var section   = (AppSettingsSection)config.GetSection("appSettings");
        var strUseSSL = section.Settings["UseSSL"].Value;
        var strPort   = section.Settings["Port"].Value;

        var dvEmail = (OdsNewsletter.Select() as DataView);
        var strHost = section.Settings["Host"].Value;
        int n;
        var isNumeric      = int.TryParse(strPort, out n);
        var iPort          = isNumeric ? n : 0;
        var strMailFrom    = section.Settings["Email"].Value;
        var strDisplayName = "News & Orders";
        var strUserName    = section.Settings["UserName"].Value;
        var strPassword    = MD5Hash.Decrypt(section.Settings["Password"].Value, true);
        var bEnableSsl     = strUseSSL.ToLower() == "true";
        var strMailTo      = "";
        var strCC          = "";
        var strSubject     = txtSubject.Text.Trim();
        var strBody        = txtContent.Content;

        if (RadGrid1.SelectedItems.Count == 0)
        {
            //strMailTo = (from DataRowView drv in dvEmail select drv["Email"].ToString()).ToList<string>().Aggregate((a, b) => a + ',' + b);
            if (dvEmail != null && dvEmail.Count > 0)
            {
                foreach (DataRow drv in dvEmail.Table.Rows)
                {
                    strMailTo = drv["Email"].ToString();
                    Common.SendMail(
                        strHost,
                        iPort,
                        strMailFrom,
                        strDisplayName,
                        strUserName,
                        strPassword,
                        strMailTo,
                        strCC,
                        strSubject,
                        strBody,
                        bEnableSsl
                        );
                }
            }
        }
        else
        {
            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                strMailTo = item["Email"].Text;
                Common.SendMail(
                    strHost,
                    iPort,
                    strMailFrom,
                    strDisplayName,
                    strUserName,
                    strPassword,
                    strMailTo,
                    strCC,
                    strSubject,
                    strBody,
                    bEnableSsl
                    );
            }
        }
        clearText();
        lblSucess.Text = "Email has been send.";
    }